Re: [util-linux] readprofile ignores the last element in /proc/profile

William Lee Irwin III
2004-09-01T00:32:45Z

On Tue, Aug 31, 2004 at 12:25:59PM -0700, William Lee Irwin III wrote:
> > - if (read(state->fd, state->buf, end - start) == end - start) {
> > - for (off = 0; off < (end - start)/sizeof(uint32_t); ++off)
> > + if ((state->bufcnt = read(state->fd, state->buf, end - start)) >= 0) {
> > + for (off = 0; off < (state->bufcnt)/sizeof(uint32_t); ++off)
> > state->last->hits += state->buf[off];

Still wrong =( That needs to be strict inequality.

--- readprofile.c.orig2 2004-08-31 12:11:54.000000000 -0700
+++ readprofile.c 2004-08-31 12:44:25.000000000 -0700
@@ -65,6 +65,7 @@
int ret = 0;
long page_mask, start, end;
unsigned off;
+ ssize_t bufcnt;

if (!state->stext) {
if (!strcmp(state->sym, "_stext"))
@@ -101,8 +102,8 @@
exit(EXIT_FAILURE);
}
}
- if (read(state->fd, state->buf, end - start) == end - start) {
- for (off = 0; off < (end - start)/sizeof(uint32_t); ++off)
+ if ((bufcnt = read(state->fd, state->buf, end - start)) > 0) {
+ for (off = 0; off < bufcnt/sizeof(uint32_t); ++off)
state->last->hits += state->buf[off];
} else {
ret = 1;