bsdgrep: fix EOF handling with --mmap
Rework part of the loop in grep_fgetln to return the rest of the line and ensure that we still advance the buffer by the length of the rest of the line. PR: 165471 Submitted by: Kyle Evans <kevans91@ksu.edu> MFC after: 1 month
This commit is contained in:
parent
c6d57d3073
commit
5dff7be120
Notes:
svn2git
2020-12-20 02:59:44 +00:00
svn path=/head/; revision=313948
@ -219,12 +219,18 @@ grep_fgetln(struct file *f, size_t *lenp)
|
||||
if (bufrem == 0)
|
||||
/* EOF: return partial line */
|
||||
break;
|
||||
if ((p = memchr(bufpos, '\n', bufrem)) == NULL)
|
||||
if ((p = memchr(bufpos, '\n', bufrem)) == NULL &&
|
||||
filebehave != FILE_MMAP)
|
||||
continue;
|
||||
/* got it: finish up the line (like code above) */
|
||||
++p;
|
||||
diff = p - bufpos;
|
||||
len += diff;
|
||||
if (p == NULL) {
|
||||
/* mmap EOF: return partial line, consume buffer */
|
||||
diff = len;
|
||||
} else {
|
||||
/* 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);
|
||||
|
Loading…
Reference in New Issue
Block a user