From 1bc34ffa64c33381d793fb5cdddf3f484e603d23 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Carlo=20Marcelo=20Arenas=20Bel=C3=B3n?= <carenas@gmail.com>
Date: Fri, 12 May 2023 07:54:02 -0700
Subject: [PATCH] pcre2grep: document better possible multiline matching misses
 (#252)

While at it, remove a misplaced cast that would cause problems for
subjects over 2GB and a few typos.

Conflict:adapt context
Reference:https://github.com/PCRE2Project/pcre2/commit/1bc34ffa64c33381d793fb5cdddf3f484e603d23
---
 doc/pcre2grep.1     | 11 ++++++++---
 src/pcre2_compile.c |  4 ++--
 src/pcre2grep.c     |  2 +-
 3 files changed, 11 insertions(+), 6 deletions(-)

diff --git a/doc/pcre2grep.1 b/doc/pcre2grep.1
index 1081591..5077304 100644
--- a/doc/pcre2grep.1
+++ b/doc/pcre2grep.1
@@ -66,6 +66,9 @@ The block of memory that is actually used is three times the "buffer size", to
 allow for buffering "before" and "after" lines. If the buffer size is too
 small, fewer than requested "before" and "after" lines may be output.
 .P
+When matching with a multiline pattern, the size of the buffer must be at least
+half of the maximum match expected or the pattern might fail to match.
+.P
 Patterns can be no longer than 8KiB or BUFSIZ bytes, whichever is the greater.
 BUFSIZ is defined in \fB<stdio.h>\fP. When there is more than one pattern
 (specified by the use of \fB-e\fP and/or \fB-f\fP), each pattern is applied to
@@ -201,7 +204,7 @@ exactly the same as the number of lines that would have been output, but if the
 \fB-M\fP (multiline) option is used (without \fB-v\fP), there may be more
 suppressed lines than the count (that is, the number of matches).
 .sp
-If no lines are selected, the number zero is output. If several files are are
+If no lines are selected, the number zero is output. If several files are
 being scanned, a count is output for each of them and the \fB-t\fP option can
 be used to cause a total to be output at the end. However, if the
 \fB--files-with-matches\fP option is also used, only those files whose counts
@@ -490,8 +493,10 @@ well as possibly handling a two-character newline sequence.
 .sp
 There is a limit to the number of lines that can be matched, imposed by the way
 that \fBpcre2grep\fP buffers the input file as it scans it. With a sufficiently
-large processing buffer, this should not be a problem, but the \fB-M\fP option
-does not work when input is read line by line (see \fB--line-buffered\fP.)
+large processing buffer, this should not be a problem.
+.sp
+The \fB-M\fP option does not work when input is read line by line (see
+\fB--line-buffered\fP.)
 .TP
 \fB-m\fP \fInumber\fP, \fB--max-count\fP=\fInumber\fP
 Stop processing after finding \fInumber\fP matching lines, or non-matching
diff --git a/src/pcre2_compile.c b/src/pcre2_compile.c
index b906dc0..c6d4c60 100644
--- a/src/pcre2_compile.c
+++ b/src/pcre2_compile.c
@@ -5549,8 +5549,8 @@ for (;; pptr++)
 
     If the class contains characters outside the 0-255 range, a different
     opcode is compiled. It may optionally have a bit map for characters < 256,
-    but those above are are explicitly listed afterwards. A flag code unit
-    tells whether the bitmap is present, and whether this is a negated class or
+    but those above are explicitly listed afterwards. A flag code unit tells
+    whether the bitmap is present, and whether this is a negated class or
     not. */
 
     case META_CLASS_NOT:
diff --git a/src/pcre2grep.c b/src/pcre2grep.c
index 1484d67..d2ab620 100644
--- a/src/pcre2grep.c
+++ b/src/pcre2grep.c
@@ -1843,7 +1843,7 @@ if (slen > 200)
 
 for (i = 1; p != NULL; p = p->next, i++)
   {
-  *mrc = pcre2_match(p->compiled, (PCRE2_SPTR)matchptr, (int)length,
+  *mrc = pcre2_match(p->compiled, (PCRE2_SPTR)matchptr, length,
     startoffset, options, match_data, match_context);
   if (*mrc >= 0) return TRUE;
   if (*mrc == PCRE2_ERROR_NOMATCH) continue;
-- 
2.27.0

