From 347d7363ce19c1e897c87f17394cacaaef230c1f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Petr=20P=C3=ADsa=C5=99?= Date: Fri, 22 Dec 2017 14:48:04 +0100 Subject: [PATCH] Allow pcre2grep match counter to handle values larger than 2147483647 --- ...-line-number-and-count-variables-to-.patch | 137 ++++++++++++++++++ pcre2.spec | 6 + 2 files changed, 143 insertions(+) create mode 100644 pcre2-10.30-Change-pcre2grep-line-number-and-count-variables-to-.patch diff --git a/pcre2-10.30-Change-pcre2grep-line-number-and-count-variables-to-.patch b/pcre2-10.30-Change-pcre2grep-line-number-and-count-variables-to-.patch new file mode 100644 index 0000000..34421cf --- /dev/null +++ b/pcre2-10.30-Change-pcre2grep-line-number-and-count-variables-to-.patch @@ -0,0 +1,137 @@ +From 43e13d367d3f442ace4ce1cf43d9c2b27e2226bb Mon Sep 17 00:00:00 2001 +From: ph10 +Date: Fri, 8 Dec 2017 10:25:49 +0000 +Subject: [PATCH] Change pcre2grep line number and count variables to unsigned + long int. +MIME-Version: 1.0 +Content-Type: text/plain; charset=UTF-8 +Content-Transfer-Encoding: 8bit + +git-svn-id: svn://vcs.exim.org/pcre2/code/trunk@887 6239d852-aaf2-0410-a92c-79f79f948069 + +Petr Písař: Port to 10.30. +diff --git a/src/pcre2grep.c b/src/pcre2grep.c +index c7c95c5..e764313 100644 +--- a/src/pcre2grep.c ++++ b/src/pcre2grep.c +@@ -196,8 +196,9 @@ static int bufthird = PCRE2GREP_BUFSIZE; + static int max_bufthird = PCRE2GREP_MAX_BUFSIZE; + static int bufsize = 3*PCRE2GREP_BUFSIZE; + static int endlinetype; +-static int total_count = 0; +-static int counts_printed = 0; ++ ++static unsigned long int total_count = 0; ++static unsigned long int counts_printed = 0; + + #ifdef WIN32 + static int dee_action = dee_SKIP; +@@ -1606,8 +1607,8 @@ Returns: nothing + */ + + static void +-do_after_lines(int lastmatchnumber, char *lastmatchrestart, char *endptr, +- const char *printname) ++do_after_lines(unsigned long int lastmatchnumber, char *lastmatchrestart, ++ char *endptr, const char *printname) + { + if (after_context > 0 && lastmatchnumber > 0) + { +@@ -1618,7 +1619,7 @@ if (after_context > 0 && lastmatchnumber > 0) + char *pp = end_of_line(lastmatchrestart, endptr, &ellength); + if (ellength == 0 && pp == main_buffer + bufsize) break; + if (printname != NULL) fprintf(stdout, "%s-", printname); +- if (number) fprintf(stdout, "%d-", lastmatchnumber++); ++ if (number) fprintf(stdout, "%lu-", lastmatchnumber++); + FWRITE_IGNORE(lastmatchrestart, 1, pp - lastmatchrestart, stdout); + lastmatchrestart = pp; + count++; +@@ -2309,10 +2310,10 @@ static int + pcre2grep(void *handle, int frtype, const char *filename, const char *printname) + { + int rc = 1; +-int linenumber = 1; +-int lastmatchnumber = 0; +-int count = 0; + int filepos = 0; ++unsigned long int linenumber = 1; ++unsigned long int lastmatchnumber = 0; ++unsigned long int count = 0; + char *lastmatchrestart = NULL; + char *ptr = main_buffer; + char *endptr; +@@ -2400,7 +2401,7 @@ while (ptr < endptr) + if (new_buffer == NULL) + { + fprintf(stderr, +- "pcre2grep: line %d%s%s is too long for the internal buffer\n" ++ "pcre2grep: line %lu%s%s is too long for the internal buffer\n" + "pcre2grep: not enough memory to increase the buffer size to %d\n", + linenumber, + (filename == NULL)? "" : " of file ", +@@ -2430,7 +2431,7 @@ while (ptr < endptr) + else + { + fprintf(stderr, +- "pcre2grep: line %d%s%s is too long for the internal buffer\n" ++ "pcre2grep: line %lu%s%s is too long for the internal buffer\n" + "pcre2grep: the maximum buffer size is %d\n" + "pcre2grep: use the --max-buffer-size option to change it\n", + linenumber, +@@ -2562,7 +2563,7 @@ while (ptr < endptr) + size_t oldstartoffset; + + if (printname != NULL) fprintf(stdout, "%s:", printname); +- if (number) fprintf(stdout, "%d:", linenumber); ++ if (number) fprintf(stdout, "%lu:", linenumber); + + /* Handle --line-offsets */ + +@@ -2682,7 +2683,7 @@ while (ptr < endptr) + { + char *pp = lastmatchrestart; + if (printname != NULL) fprintf(stdout, "%s-", printname); +- if (number) fprintf(stdout, "%d-", lastmatchnumber++); ++ if (number) fprintf(stdout, "%lu-", lastmatchnumber++); + pp = end_of_line(pp, endptr, &ellength); + FWRITE_IGNORE(lastmatchrestart, 1, pp - lastmatchrestart, stdout); + lastmatchrestart = pp; +@@ -2722,7 +2723,7 @@ while (ptr < endptr) + int ellength; + char *pp = p; + if (printname != NULL) fprintf(stdout, "%s-", printname); +- if (number) fprintf(stdout, "%d-", linenumber - linecount--); ++ if (number) fprintf(stdout, "%lu-", linenumber - linecount--); + pp = end_of_line(pp, endptr, &ellength); + FWRITE_IGNORE(p, 1, pp - p, stdout); + p = pp; +@@ -2736,7 +2737,7 @@ while (ptr < endptr) + endhyphenpending = TRUE; + + if (printname != NULL) fprintf(stdout, "%s:", printname); +- if (number) fprintf(stdout, "%d:", linenumber); ++ if (number) fprintf(stdout, "%lu:", linenumber); + + /* This extra option, for Jeffrey Friedl's debugging requirements, + replaces the matched string, or a specific captured string if it exists, +@@ -2918,7 +2919,7 @@ if (count_only && !quiet) + { + if (printname != NULL && filenames != FN_NONE) + fprintf(stdout, "%s:", printname); +- fprintf(stdout, "%d" STDOUT_NL, count); ++ fprintf(stdout, "%lu" STDOUT_NL, count); + counts_printed++; + } + } +@@ -4196,7 +4197,7 @@ if (show_total_count && counts_printed != 1 && filenames != FN_NOMATCH_ONLY) + { + if (counts_printed != 0 && filenames >= FN_DEFAULT) + fprintf(stdout, "TOTAL:"); +- fprintf(stdout, "%d" STDOUT_NL, total_count); ++ fprintf(stdout, "%lu" STDOUT_NL, total_count); + } + + EXIT: +-- +2.13.6 + diff --git a/pcre2.spec b/pcre2.spec index c97b69b..7e63234 100644 --- a/pcre2.spec +++ b/pcre2.spec @@ -56,6 +56,9 @@ Patch4: pcre2-10.30-Fix-multiple-multiline-matching-issues-in-pcre2grep.patc # Fix pcre2_jit_match() to properly check the pattern was JIT-compiled, # in upstream after 10.30 Patch5: pcre2-10.30-Fix-pcre2_jit_match-early-check.patch +# Allow pcre2grep match counter to handle values larger than 2147483647, +# upstream bug #2208, in upstream after 10.30 +Patch6: pcre2-10.30-Change-pcre2grep-line-number-and-count-variables-to-.patch BuildRequires: autoconf BuildRequires: automake BuildRequires: coreutils @@ -135,6 +138,7 @@ Utilities demonstrating PCRE2 capabilities like pcre2grep or pcre2test. %patch3 -p1 %patch4 -p1 %patch5 -p1 +%patch6 -p1 # Because of multilib patch libtoolize --copy --force autoreconf -vif @@ -240,6 +244,8 @@ make %{?_smp_mflags} check VERBOSE=yes %changelog * Fri Dec 22 2017 Petr Pisar - 10.30-4 - Fix pcre2_jit_match() to properly check the pattern was JIT-compiled +- Allow pcre2grep match counter to handle values larger than 2147483647, + (upstream bug #2208) * Mon Nov 13 2017 Petr Pisar - 10.30-3 - Fix multi-line matching in pcre2grep tool (upstream bug #2187)