diff options
author | ph10 <ph10@2f5784b3-3f2a-0410-8824-cb99058d5e15> | 2007-08-17 10:48:51 +0000 |
---|---|---|
committer | ph10 <ph10@2f5784b3-3f2a-0410-8824-cb99058d5e15> | 2007-08-17 10:48:51 +0000 |
commit | 2577186e689baff05e3842bb78f1fc9f88c3b498 (patch) | |
tree | fa9b952cb166dda5a3b5fee05a392aeb9bc45ddf | |
parent | 996a1205f65d319c3e699e599860cb379c150027 (diff) | |
download | pcre-2577186e689baff05e3842bb78f1fc9f88c3b498.tar.gz |
Fix pcregrep -Mv looping bug.
git-svn-id: svn://vcs.exim.org/pcre/code/trunk@222 2f5784b3-3f2a-0410-8824-cb99058d5e15
-rw-r--r-- | ChangeLog | 2 | ||||
-rw-r--r-- | Makefile.am | 1 | ||||
-rwxr-xr-x | RunGrepTest | 3 | ||||
-rw-r--r-- | configure.ac | 2 | ||||
-rw-r--r-- | pcregrep.c | 37 | ||||
-rw-r--r-- | testdata/grepinputv | 3 | ||||
-rw-r--r-- | testdata/grepoutput | 2 |
7 files changed, 42 insertions, 8 deletions
@@ -143,6 +143,8 @@ Version 7.3 17-Aug-07 24. A repeated \S or \W in UTF-8 mode could give wrong answers when multibyte characters were involved (for example /\S{2}/8g with "A\x{a3}BC"). +25. Using pcregrep in multiline, inverted mode (-Mv) caused it to loop. + Version 7.2 19-Jun-07 --------------------- diff --git a/Makefile.am b/Makefile.am index 6703575..0910bbc 100644 --- a/Makefile.am +++ b/Makefile.am @@ -255,6 +255,7 @@ pcregrep_LDADD = libpcreposix.la EXTRA_DIST += \ testdata/grepinput \ testdata/grepinput8 \ + testdata/grepinputv \ testdata/grepinputx \ testdata/greplist \ testdata/grepoutput \ diff --git a/RunGrepTest b/RunGrepTest index 0e3bdc2..e46a2f3 100755 --- a/RunGrepTest +++ b/RunGrepTest @@ -202,6 +202,9 @@ elephant" ./testdata/grepinput) >>testtry echo "---------------------------- Test 49 ------------------------------" >>testtry (cd $srcdir; $valgrind $pcregrep "^(abc|def|ghi|jkl)" ./testdata/grepinputx) >>testtry +echo "---------------------------- Test 50 ------------------------------" >>testtry +(cd $srcdir; $valgrind $pcregrep -Mv "brown\sfox" ./testdata/grepinputv) >>testtry + # Now compare the results. $cf $srcdir/testdata/grepoutput testtry diff --git a/configure.ac b/configure.ac index 2b29fe4..cb534b4 100644 --- a/configure.ac +++ b/configure.ac @@ -8,7 +8,7 @@ dnl empty. m4_define(pcre_major, [7]) m4_define(pcre_minor, [3]) -m4_define(pcre_prerelease, [-RC6]) +m4_define(pcre_prerelease, [-RC7]) m4_define(pcre_date, [2007-08-17]) # Libtool shared library interface versions (current:revision:age) @@ -1064,18 +1064,23 @@ while (ptr < endptr) /* In multiline mode, we want to print to the end of the line in which the end of the matched string is found, so we adjust linelength and the - line number appropriately. Because the PCRE_FIRSTLINE option is set, the - start of the match will always be before the first newline sequence. */ + line number appropriately, but only when there actually was a match + (invert not set). Because the PCRE_FIRSTLINE option is set, the start of + the match will always be before the first newline sequence. */ if (multiline) { int ellength; - char *endmatch = ptr + offsets[1]; - t = ptr; - while (t < endmatch) + char *endmatch = ptr; + if (!invert) { - t = end_of_line(t, endptr, &ellength); - if (t <= endmatch) linenumber++; else break; + endmatch += offsets[1]; + t = ptr; + while (t < endmatch) + { + t = end_of_line(t, endptr, &ellength); + if (t <= endmatch) linenumber++; else break; + } } endmatch = end_of_line(endmatch, endptr, &ellength); linelength = endmatch - ptr - ellength; @@ -1124,6 +1129,24 @@ while (ptr < endptr) lastmatchnumber = linenumber + 1; } + /* For a match in multiline inverted mode (which of course did not cause + anything to be printed), we have to move on to the end of the match before + proceeding. */ + + if (multiline && invert && match) + { + int ellength; + char *endmatch = ptr + offsets[1]; + t = ptr; + while (t < endmatch) + { + t = end_of_line(t, endptr, &ellength); + if (t <= endmatch) linenumber++; else break; + } + endmatch = end_of_line(endmatch, endptr, &ellength); + linelength = endmatch - ptr - ellength; + } + /* Advance to after the newline and increment the line number. */ ptr += linelength + endlinelength; diff --git a/testdata/grepinputv b/testdata/grepinputv new file mode 100644 index 0000000..528153d --- /dev/null +++ b/testdata/grepinputv @@ -0,0 +1,3 @@ +The quick brown +fox jumps +over the lazy dog. diff --git a/testdata/grepoutput b/testdata/grepoutput index 2e8cdc7..d5506a1 100644 --- a/testdata/grepoutput +++ b/testdata/grepoutput @@ -383,3 +383,5 @@ AB.VE AB.VE the turtle PUT NEW DATA ABOVE THIS LINE. ---------------------------- Test 49 ------------------------------ +---------------------------- Test 50 ------------------------------ +over the lazy dog. |