|
|
7152384 |
Fix https://bugzilla.redhat.com/show_bug.cgi?id=324781
|
|
|
7152384 |
See the code comments for details.
|
|
|
7152384 |
|
|
|
7152384 |
Lubomir Rintel <lkundrak@v3.sk>
|
|
|
7152384 |
|
|
|
7152384 |
--- grep-2.5.1a/src/search.c.pcrewrap 2008-10-01 16:38:20.000000000 +0200
|
|
|
7152384 |
+++ grep-2.5.1a/src/search.c 2008-10-01 16:38:20.000000000 +0200
|
|
|
7152384 |
@@ -1241,8 +1241,31 @@
|
|
|
7152384 |
is just for performance improvement in pcre_exec. */
|
|
|
7152384 |
int sub[300];
|
|
|
7152384 |
|
|
|
7152384 |
- int e = pcre_exec (cre, extra, buf, size, 0, 0,
|
|
|
7152384 |
- sub, sizeof sub / sizeof *sub);
|
|
|
7152384 |
+ char *line_buf = buf;
|
|
|
7152384 |
+ int line_size = 0;
|
|
|
7152384 |
+ int e = 0;
|
|
|
7152384 |
+
|
|
|
7152384 |
+ /* PCRE can't limit the matching to space between newlines (i.e
|
|
|
7152384 |
+ [^a] will allways match newline, see pcreposix(3) for details),
|
|
|
7152384 |
+ therefore whe have to match each line in the buffer separately */
|
|
|
7152384 |
+ do {
|
|
|
7152384 |
+ /* We're not at the of buffer or end of line, get another char */
|
|
|
7152384 |
+ if (line_buf + line_size < buf + size && line_buf[line_size++] != eolbyte) {
|
|
|
7152384 |
+ continue;
|
|
|
7152384 |
+ }
|
|
|
7152384 |
+
|
|
|
7152384 |
+ /* Match the part of buffer that constitutes a line */
|
|
|
7152384 |
+ e = pcre_exec (cre, extra, line_buf, line_size - 1, 0, 0,
|
|
|
7152384 |
+ sub, sizeof sub / sizeof *sub);
|
|
|
7152384 |
+
|
|
|
7152384 |
+ /* Don't try other lines if this one matched or returned an error */
|
|
|
7152384 |
+ if (e != PCRE_ERROR_NOMATCH)
|
|
|
7152384 |
+ break;
|
|
|
7152384 |
+
|
|
|
7152384 |
+ /* Wrap up */
|
|
|
7152384 |
+ line_buf += line_size;
|
|
|
7152384 |
+ line_size = 0;
|
|
|
7152384 |
+ } while (line_buf < buf + size);
|
|
|
7152384 |
|
|
|
7152384 |
if (e <= 0)
|
|
|
7152384 |
{
|
|
|
7152384 |
@@ -1261,8 +1284,8 @@
|
|
|
7152384 |
else
|
|
|
7152384 |
{
|
|
|
7152384 |
/* Narrow down to the line we've found. */
|
|
|
7152384 |
- char const *beg = buf + sub[0];
|
|
|
7152384 |
- char const *end = buf + sub[1];
|
|
|
7152384 |
+ char const *beg = line_buf + sub[0];
|
|
|
7152384 |
+ char const *end = line_buf + sub[1];
|
|
|
7152384 |
char const *buflim = buf + size;
|
|
|
7152384 |
char eol = eolbyte;
|
|
|
7152384 |
if (!exact)
|
|
|
7152384 |
--- grep-2.5.1a/tests/Makefile.am.pcrewrap 2008-10-01 16:47:01.000000000 +0200
|
|
|
7152384 |
+++ grep-2.5.1a/tests/Makefile.am 2008-10-01 16:47:26.000000000 +0200
|
|
|
7152384 |
@@ -4,7 +4,7 @@
|
|
|
7152384 |
|
|
|
7152384 |
TESTS = warning.sh khadafy.sh spencer1.sh bre.sh ere.sh \
|
|
|
7152384 |
status.sh empty.sh options.sh backref.sh file.sh \
|
|
|
7152384 |
- fmbtest.sh
|
|
|
7152384 |
+ fmbtest.sh pcrewrap.sh
|
|
|
7152384 |
EXTRA_DIST = $(TESTS) \
|
|
|
7152384 |
khadafy.lines khadafy.regexp \
|
|
|
7152384 |
spencer1.awk spencer1.tests \
|
|
|
7152384 |
--- grep-2.5.1a/tests/Makefile.in.pcrewrap 2008-10-01 16:47:01.000000000 +0200
|
|
|
7152384 |
+++ grep-2.5.1a/tests/Makefile.in 2008-10-01 16:47:34.000000000 +0200
|
|
|
7152384 |
@@ -98,7 +98,7 @@
|
|
|
7152384 |
|
|
|
7152384 |
TESTS = warning.sh khadafy.sh spencer1.sh bre.sh ere.sh \
|
|
|
7152384 |
status.sh empty.sh options.sh backref.sh file.sh \
|
|
|
7152384 |
- fmbtest.sh
|
|
|
7152384 |
+ fmbtest.sh pcrewrap.sh
|
|
|
7152384 |
|
|
|
7152384 |
EXTRA_DIST = $(TESTS) \
|
|
|
7152384 |
khadafy.lines khadafy.regexp \
|
|
|
7152384 |
--- grep-2.5.1a/tests/pcrewrap.sh 2008-09-30 09:16:44.037543374 +0200
|
|
|
7152384 |
+++ grep-2.5.1a/tests/pcrewrap.sh 2008-10-01 16:45:45.000000000 +0200
|
|
|
7152384 |
@@ -0,0 +1,23 @@
|
|
|
7152384 |
+#!/bin/sh
|
|
|
7152384 |
+# Test for bug https://bugzilla.redhat.com/show_bug.cgi?id=324781
|
|
|
7152384 |
+# Lubomir Rintel <lkundrak@v3.sk>
|
|
|
7152384 |
+
|
|
|
7152384 |
+: ${srcdir=.}
|
|
|
7152384 |
+
|
|
|
7152384 |
+failures=0
|
|
|
7152384 |
+
|
|
|
7152384 |
+echo -ne "a\na" | ${GREP} -P '[^a]' > /dev/null 2>&1
|
|
|
7152384 |
+if test $? -ne 1
|
|
|
7152384 |
+then
|
|
|
7152384 |
+ echo "PCRE Wrap: Wrong status code, test \#1 failed"
|
|
|
7152384 |
+ failures=1
|
|
|
7152384 |
+fi
|
|
|
7152384 |
+
|
|
|
7152384 |
+echo -ne "a\na" | ${GREP} -P '[^b].[^b]' > /dev/null 2>&1
|
|
|
7152384 |
+if test $? -ne 1
|
|
|
7152384 |
+then
|
|
|
7152384 |
+ echo "PCRE Wrap: Wrong status code, test \#2 failed"
|
|
|
7152384 |
+ failures=1
|
|
|
7152384 |
+fi
|
|
|
7152384 |
+
|
|
|
7152384 |
+exit $failures
|
|
|
7152384 |
|