PERFORCE change 155260 for review
Gabor Kovesdan
gabor at FreeBSD.org
Wed Dec 24 20:52:25 PST 2008
http://perforce.freebsd.org/chv.cgi?CH=155260
Change 155260 by gabor at gabor_server on 2008/12/25 04:51:32
- Fix file handling bugs
Affected files ...
.. //depot/projects/soc2008/gabor_textproc/grep/file.c#34 edit
.. //depot/projects/soc2008/gabor_textproc/grep/util.c#77 edit
Differences ...
==== //depot/projects/soc2008/gabor_textproc/grep/file.c#34 (text+ko) ====
@@ -118,7 +118,7 @@
grep_fgetln(struct file *f, size_t *len)
{
int i = 0;
- char ch;
+ int ch = 0;
/* Fill in the buffer if it is empty. */
if (binbufptr == NULL) {
@@ -149,11 +149,16 @@
lnbuflen *= 2;
lnbuf = grep_realloc(lnbuf, ++lnbuflen);
}
- if (ch == '\n')
+ if (ch == '\n') {
+ lnbuf[i] = '\0';
+ break;
+ }
+ if (ch != EOF)
+ lnbuf[i] = ch;
+ else
break;
- lnbuf[i] = ch;
}
- if (grep_feof(f) && (i == 0))
+ if (grep_feof(f) && (i == 0) && (ch != '\n'))
return (NULL);
*len = i;
return (lnbuf);
@@ -228,4 +233,8 @@
break;
}
free(f);
+
+ /* Reset read buffer for the file we are closing */
+ binbufptr = NULL;
+
}
==== //depot/projects/soc2008/gabor_textproc/grep/util.c#77 (text+ko) ====
@@ -114,8 +114,6 @@
} else
ok = 1;
if (ok)
- /* Reset read buffer before reading other file */
- binbufptr = NULL;
c += procfile(p->fts_path);
break;
}
More information about the p4-projects
mailing list