| 1 |
From 0c56b664a73764ed01607f47731c8e4607f478d5 Mon Sep 17 00:00:00 2001
|
| 2 |
From: Lubomir Rintel <lkundrak@v3.sk>
|
| 3 |
Date: Sun, 23 Nov 2008 17:25:57 +0100
|
| 4 |
Subject: [PATCH] Fix line wrapping in PCRE backend
|
| 5 |
|
| 6 |
PCRE can't limit the matching to space between newlines (i.e
|
| 7 |
[^a] will allways match newline, see pcreposix(3) for details),
|
| 8 |
therefore whe have to split the buffer into lines and match each
|
| 9 |
line in the buffer separately.
|
| 10 |
|
| 11 |
Original ticket: https://bugzilla.redhat.com/show_bug.cgi?id=324781
|
| 12 |
---
|
| 13 |
src/search.c | 33 ++++++++++++++++++++++++++++-----
|
| 14 |
1 files changed, 28 insertions(+), 5 deletions(-)
|
| 15 |
|
| 16 |
diff --git a/src/search.c b/src/search.c
|
| 17 |
index 0b3e0e8..7f5f187 100644
|
| 18 |
--- a/src/search.c
|
| 19 |
+++ b/src/search.c
|
| 20 |
@@ -689,9 +689,32 @@ EXECUTE_FCT(Pexecute)
|
| 21 |
is just for performance improvement in pcre_exec. */
|
| 22 |
int sub[300];
|
| 23 |
|
| 24 |
- int e = pcre_exec (cre, extra, buf, size,
|
| 25 |
- start_ptr ? (start_ptr - buf) : 0, 0,
|
| 26 |
- sub, sizeof sub / sizeof *sub);
|
| 27 |
+ char *line_buf = buf;
|
| 28 |
+ int line_size = 0;
|
| 29 |
+ int e = 0;
|
| 30 |
+
|
| 31 |
+ /* PCRE can't limit the matching to space between newlines (i.e
|
| 32 |
+ [^a] will allways match newline, see pcreposix(3) for details),
|
| 33 |
+ therefore whe have to match each line in the buffer separately */
|
| 34 |
+ do {
|
| 35 |
+ /* We're not at the of buffer or end of line, get another char */
|
| 36 |
+ if (line_buf + line_size < buf + size && line_buf[line_size++] != eolbyte) {
|
| 37 |
+ continue;
|
| 38 |
+ }
|
| 39 |
+
|
| 40 |
+ /* Match the part of buffer that constitutes a line */
|
| 41 |
+ e = pcre_exec (cre, extra, line_buf, line_size - 1,
|
| 42 |
+ start_ptr ? (start_ptr - buf) : 0, 0,
|
| 43 |
+ sub, sizeof sub / sizeof *sub);
|
| 44 |
+
|
| 45 |
+ /* Don't try other lines if this one matched or returned an error */
|
| 46 |
+ if (e != PCRE_ERROR_NOMATCH)
|
| 47 |
+ break;
|
| 48 |
+
|
| 49 |
+ /* Wrap up */
|
| 50 |
+ line_buf += line_size;
|
| 51 |
+ line_size = 0;
|
| 52 |
+ } while (line_buf < buf + size);
|
| 53 |
|
| 54 |
if (e <= 0)
|
| 55 |
{
|
| 56 |
@@ -710,8 +733,8 @@ EXECUTE_FCT(Pexecute)
|
| 57 |
else
|
| 58 |
{
|
| 59 |
/* Narrow down to the line we've found. */
|
| 60 |
- char const *beg = buf + sub[0];
|
| 61 |
- char const *end = buf + sub[1];
|
| 62 |
+ char const *beg = line_buf + sub[0];
|
| 63 |
+ char const *end = line_buf + sub[1];
|
| 64 |
char const *buflim = buf + size;
|
| 65 |
char eol = eolbyte;
|
| 66 |
if (!start_ptr)
|
| 67 |
--
|
| 68 |
1.5.5.1
|
| 69 |
|