diff options
author | Charles Levert <charles_levert@gna.org> | 2005-06-21 04:55:26 +0000 |
---|---|---|
committer | Charles Levert <charles_levert@gna.org> | 2005-06-21 04:55:26 +0000 |
commit | 6efca6e7e7e973ac8941c8694cb956efc9764164 (patch) | |
tree | 9fdbdba7d1da20adfe0fa86db1053f7f31b81844 | |
parent | 5c213dc5f275c6db2b590dc0c7ae476e65603838 (diff) | |
download | grep-6efca6e7e7e973ac8941c8694cb956efc9764164.tar.gz |
* src/grep.c (nlscan): Make this function more robust by removing
the undocumented assumption that its "lim" argument points
right after a line boundary. This will be used later to fix
--byte-offset's broken behavior. Patch #3769.
-rw-r--r-- | ChangeLog | 7 | ||||
-rw-r--r-- | src/grep.c | 9 |
2 files changed, 14 insertions, 2 deletions
@@ -1,3 +1,10 @@ +2005-06-21 Charles Levert <charles_levert@gna.org> + + * src/grep.c (nlscan): Make this function more robust by removing + the undocumented assumption that its "lim" argument points + right after a line boundary. This will be used later to fix + --byte-offset's broken behavior. Patch #3769. + 2005-06-20 Charles Levert <charles_levert@gna.org> * src/grep.c: Extensively document the SGR/EL-to-Right issue. @@ -589,8 +589,13 @@ nlscan (char const *lim) { size_t newlines = 0; char const *beg; - for (beg = lastnl; beg != lim; beg = memchr (beg, eolbyte, lim - beg), beg++) - newlines++; + for (beg = lastnl; beg < lim; beg++) + { + beg = memchr (beg, eolbyte, lim - beg); + if (!beg) + break; + newlines++; + } totalnl = add_count (totalnl, newlines); lastnl = lim; } |