Allow pcregrep match counter to handle values larger than 2147483647

This commit is contained in:
Petr Písař 2018-01-12 14:39:10 +01:00
parent aaf579eb22
commit 13135a397c
2 changed files with 118 additions and 1 deletions

View File

@ -0,0 +1,109 @@
From faeb061701c6875684eccc463b1a325e6c9a31af Mon Sep 17 00:00:00 2001
From: ph10 <ph10@2f5784b3-3f2a-0410-8824-cb99058d5e15>
Date: Fri, 8 Dec 2017 14:09:22 +0000
Subject: [PATCH] Change pcregrep linenumbers and counts to long ints.
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
git-svn-id: svn://vcs.exim.org/pcre/code/trunk@1718 2f5784b3-3f2a-0410-8824-cb99058d5e15
Petr Písař: Ported to 8.41.
---
pcregrep.c | 24 ++++++++++++------------
diff --git a/pcregrep.c b/pcregrep.c
index a81c88d..628fac4 100644
--- a/pcregrep.c
+++ b/pcregrep.c
@@ -1387,8 +1387,8 @@ Returns: nothing
*/
static void
-do_after_lines(int lastmatchnumber, char *lastmatchrestart, char *endptr,
- char *printname)
+do_after_lines(unsigned long int lastmatchnumber, char *lastmatchrestart,
+ char *endptr, char *printname)
{
if (after_context > 0 && lastmatchnumber > 0)
{
@@ -1398,7 +1398,7 @@ if (after_context > 0 && lastmatchnumber > 0)
int ellength;
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(lastmatchrestart, 1, pp - lastmatchrestart, stdout);
lastmatchrestart = pp;
@@ -1502,11 +1502,11 @@ static int
pcregrep(void *handle, int frtype, char *filename, char *printname)
{
int rc = 1;
-int linenumber = 1;
-int lastmatchnumber = 0;
-int count = 0;
int filepos = 0;
int offsets[OFFSET_SIZE];
+unsigned long int linenumber = 1;
+unsigned long int lastmatchnumber = 0;
+unsigned long int count = 0;
char *lastmatchrestart = NULL;
char *ptr = main_buffer;
char *endptr;
@@ -1609,7 +1609,7 @@ while (ptr < endptr)
if (endlinelength == 0 && t == main_buffer + bufsize)
{
- fprintf(stderr, "pcregrep: line %d%s%s is too long for the internal buffer\n"
+ fprintf(stderr, "pcregrep: line %lu%s%s is too long for the internal buffer\n"
"pcregrep: check the --buffer-size option\n",
linenumber,
(filename == NULL)? "" : " of file ",
@@ -1747,7 +1747,7 @@ while (ptr < endptr)
prevoffsets[1] = offsets[1];
if (printname != NULL) fprintf(stdout, "%s:", printname);
- if (number) fprintf(stdout, "%d:", linenumber);
+ if (number) fprintf(stdout, "%lu:", linenumber);
/* Handle --line-offsets */
@@ -1862,7 +1862,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(lastmatchrestart, 1, pp - lastmatchrestart, stdout);
lastmatchrestart = pp;
@@ -1902,7 +1902,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(p, 1, pp - p, stdout);
p = pp;
@@ -1916,7 +1916,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);
/* 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
@@ -2112,7 +2112,7 @@ if (count_only && !quiet)
{
if (printname != NULL && filenames != FN_NONE)
fprintf(stdout, "%s:", printname);
- fprintf(stdout, "%d\n", count);
+ fprintf(stdout, "%lu\n", count);
}
}
--
2.13.6

View File

@ -2,7 +2,7 @@
#%%global rcversion RC1
Name: pcre
Version: 8.41
Release: %{?rcversion:0.}3%{?rcversion:.%rcversion}%{?dist}
Release: %{?rcversion:0.}4%{?rcversion:.%rcversion}%{?dist}
%global myversion %{version}%{?rcversion:-%rcversion}
Summary: Perl-compatible regular expression library
## Source package only:
@ -41,6 +41,9 @@ Patch3: pcre-8.41-Fix-pcregrep-recursive-file-name-issue.patch
# 2/2 Accept files names longer than 128 bytes in recursive mode of pcregrep,
# upstream bug #2177, in upstream after 8.41
Patch4: pcre-8.41-Fix-possible-memory-leak-introduced-in-previous-bug-.patch
# Allow pcregrep match counter to handle values larger than 2147483647,
# upstream bug #2208, in upstream after 8.41
Patch5: pcre-8.41-Change-pcregrep-linenumbers-and-counts-to-long-ints.patch
BuildRequires: readline-devel
BuildRequires: autoconf
BuildRequires: automake
@ -127,6 +130,7 @@ Utilities demonstrating PCRE capabilities like pcregrep or pcretest.
%patch2 -p2
%patch3 -p1
%patch4 -p1
%patch5 -p1
# Because of rpath patch
libtoolize --copy --force
autoreconf -vif
@ -228,6 +232,10 @@ make %{?_smp_mflags} check VERBOSE=yes
%{_mandir}/man1/pcretest.*
%changelog
* Fri Jan 12 2018 Petr Pisar <ppisar@redhat.com> - 8.41-4
- Allow pcregrep match counter to handle values larger than 2147483647
(upstream bug #2208)
* Thu Nov 02 2017 Petr Pisar <ppisar@redhat.com> - 8.41-3
- Accept files names longer than 128 bytes in recursive mode of pcregrep
(upstream bug #2177)