From: Bruno Haible Date: Sun, 23 May 2010 23:58:56 +0000 (+0200) Subject: Bug fix: Don't assume that the buffer ends with a newline. X-Git-Tag: v0.18.1~33 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=c5f32102699222e73e4019c9ce2ba55cbf08767f;p=thirdparty%2Fgettext.git Bug fix: Don't assume that the buffer ends with a newline. --- diff --git a/gettext-tools/libgrep/ChangeLog b/gettext-tools/libgrep/ChangeLog index a1a407e86..1409a7e8f 100644 --- a/gettext-tools/libgrep/ChangeLog +++ b/gettext-tools/libgrep/ChangeLog @@ -5,6 +5,15 @@ * kwset.h: Likewise. * kwset.c: Likewise. +2010-05-23 Bruno Haible + + Fix bug: A regex was not regonized when it matched the end of the last + line and that last line was not terminated with a newline. + * m-regex.c (EGexecute): Don't ignore the last byte of the buffer if it + is not a newline. + * m-fgrep.c (Fexecute): Don't assume that the buffer contains a + newline. + 2010-05-23 Bruno Haible Do regex matching purely with regex, not regex + dfa + kwset. diff --git a/gettext-tools/libgrep/m-fgrep.c b/gettext-tools/libgrep/m-fgrep.c index 23c4d85d3..1711cec67 100644 --- a/gettext-tools/libgrep/m-fgrep.c +++ b/gettext-tools/libgrep/m-fgrep.c @@ -233,7 +233,10 @@ Fexecute (const void *compiled_pattern, const char *buf, size_t buf_size, success: end = (const char *) memchr (beg + len, eol, (buf + buf_size) - (beg + len)); - end++; + if (end != NULL) + end++; + else + end = buf + buf_size; while (buf < beg && beg[-1] != eol) --beg; *match_size = end - beg; diff --git a/gettext-tools/libgrep/m-regex.c b/gettext-tools/libgrep/m-regex.c index 5044fb78d..8af10dfdc 100644 --- a/gettext-tools/libgrep/m-regex.c +++ b/gettext-tools/libgrep/m-regex.c @@ -155,17 +155,16 @@ EGexecute (const void *compiled_pattern, for (beg = buf; beg < buflim; beg = end) { end = (const char *) memchr (beg, eol, buflim - beg); - if (end != NULL) - end++; - else + if (end == NULL) end = buflim; + /* Here, either end < buflim && *end == eol, or end == buflim. */ for (i = 0; i < cregex->pcount; i++) { - cregex->patterns[i].regexbuf.not_eol = 0; + cregex->patterns[i].regexbuf.not_eol = (end == buflim); if (0 <= (start = re_search (&(cregex->patterns[i].regexbuf), beg, - end - beg - 1, 0, - end - beg - 1, &(cregex->patterns[i].regs)))) + end - beg, 0, + end - beg, &(cregex->patterns[i].regs)))) { len = cregex->patterns[i].regs.end[0] - start; if (exact) @@ -174,7 +173,7 @@ EGexecute (const void *compiled_pattern, return start; } if ((!cregex->match_lines && !cregex->match_words) - || (cregex->match_lines && len == end - beg - 1)) + || (cregex->match_lines && len == end - beg)) goto success; /* If -w, check if the match aligns with word boundaries. We do this iteratively because: @@ -187,7 +186,7 @@ EGexecute (const void *compiled_pattern, while (start >= 0) { if ((start == 0 || !IS_WORD_CONSTITUENT ((unsigned char) beg[start - 1])) - && (len == end - beg - 1 + && (len == end - beg || !IS_WORD_CONSTITUENT ((unsigned char) beg[start + len]))) goto success; if (len > 0) @@ -202,19 +201,22 @@ EGexecute (const void *compiled_pattern, if (len <= 0) { /* Try looking further on. */ - if (start == end - beg - 1) + if (start == end - beg) break; ++start; - cregex->patterns[i].regexbuf.not_eol = 0; + cregex->patterns[i].regexbuf.not_eol = (end == buflim); start = re_search (&(cregex->patterns[i].regexbuf), beg, - end - beg - 1, - start, end - beg - 1 - start, + end - beg, + start, end - beg - start, &(cregex->patterns[i].regs)); len = cregex->patterns[i].regs.end[0] - start; } } } } /* for Regex patterns. */ + + if (end < buflim) + end++; } /* for (beg = end ..) */ return (size_t) -1;