summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCharles Levert <charles_levert@gna.org>2005-06-21 04:55:26 +0000
committerCharles Levert <charles_levert@gna.org>2005-06-21 04:55:26 +0000
commit6efca6e7e7e973ac8941c8694cb956efc9764164 (patch)
tree9fdbdba7d1da20adfe0fa86db1053f7f31b81844
parent5c213dc5f275c6db2b590dc0c7ae476e65603838 (diff)
downloadgrep-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--ChangeLog7
-rw-r--r--src/grep.c9
2 files changed, 14 insertions, 2 deletions
diff --git a/ChangeLog b/ChangeLog
index 4a61c218..c3ced5d2 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -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.
diff --git a/src/grep.c b/src/grep.c
index 5c5f6fd7..e5152bc1 100644
--- a/src/grep.c
+++ b/src/grep.c
@@ -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;
}