Page Menu
Home
FreeBSD
Search
Configure Global Search
Log In
Files
F167133168
D10820.id28569.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Flag For Later
Award Token
Size
1 KB
Referenced Files
None
Subscribers
None
D10820.id28569.diff
View Options
Index: usr.bin/grep/file.c
===================================================================
--- usr.bin/grep/file.c
+++ usr.bin/grep/file.c
@@ -213,29 +213,32 @@
if (grep_lnbufgrow(len + LNBUFBUMP))
goto error;
memcpy(lnbuf + off, bufpos, len - off);
- off = len;
- if (grep_refill(f) != 0)
- goto error;
- if (bufrem == 0)
- /* EOF: return partial line */
- break;
- if ((p = memchr(bufpos, fileeol, bufrem)) == NULL &&
- filebehave != FILE_MMAP)
- continue;
- if (p == NULL) {
- /* mmap EOF: return partial line, consume buffer */
- diff = len;
- } else {
+ /*
+ * If we've mmap()'d, then grep_refill will do nothing;
+ * otherwise, there's a chance it will reveal a newline in
+ * a part of the file we've not read yet, so keep going until
+ * we hit EOL or EOF.
+ */
+ if (filebehave != FILE_MMAP) {
+ off = len;
+ if (grep_refill(f) != 0)
+ goto error;
+ if (bufrem == 0)
+ /* EOF: return partial line */
+ break;
+ if ((p = memchr(bufpos, fileeol, bufrem)) == NULL)
+ continue;
/* got it: finish up the line (like code above) */
++p;
diff = p - bufpos;
len += diff;
- }
- if (grep_lnbufgrow(len))
- goto error;
- memcpy(lnbuf + off, bufpos, diff);
- bufrem -= diff;
- bufpos = p;
+ if (grep_lnbufgrow(len))
+ goto error;
+ memcpy(lnbuf + off, bufpos, diff);
+ bufrem -= diff;
+ bufpos = p;
+ } else
+ bufrem -= len;
break;
}
*lenp = len;
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Thu, Aug 20, 9:06 AM (5 h, 43 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
36987165
Default Alt Text
D10820.id28569.diff (1 KB)
Attached To
Mode
D10820: bsdgrep(1): Fix --mmap behavior
Attached
Detach File
Event Timeline
Log In to Comment