[Pcre-svn] [887] code/trunk: Change pcre2grep line number an…

Top Page
Delete this message
Author: Subversion repository
Date:  
To: pcre-svn
Subject: [Pcre-svn] [887] code/trunk: Change pcre2grep line number and count variables to unsigned long int.
Revision: 887
          http://www.exim.org/viewvc/pcre2?view=rev&revision=887
Author:   ph10
Date:     2017-12-08 10:25:49 +0000 (Fri, 08 Dec 2017)
Log Message:
-----------
Change pcre2grep line number and count variables to unsigned long int.


Modified Paths:
--------------
    code/trunk/ChangeLog
    code/trunk/src/pcre2grep.c


Modified: code/trunk/ChangeLog
===================================================================
--- code/trunk/ChangeLog    2017-11-30 08:15:28 UTC (rev 886)
+++ code/trunk/ChangeLog    2017-12-08 10:25:49 UTC (rev 887)
@@ -60,7 +60,12 @@
 This is fixed and pcre2_jit_match returns with PCRE2_ERROR_JIT_BADOPTION
 when the pattern is not optimized by JIT at all.


+16. The line number and related variables such as match counts in pcre2grep
+were all int variables, causing overflow when files with more than 2147483647
+lines were processed (assuming 32-bit ints). They have all been changed to
+unsigned long ints.

+
Version 10.30 14-August-2017
----------------------------


Modified: code/trunk/src/pcre2grep.c
===================================================================
--- code/trunk/src/pcre2grep.c    2017-11-30 08:15:28 UTC (rev 886)
+++ code/trunk/src/pcre2grep.c    2017-12-08 10:25:49 UTC (rev 887)
@@ -196,9 +196,10 @@
 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;
#else
@@ -1606,8 +1607,8 @@
*/

 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 @@
     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 @@
 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 @@
       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 @@
     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 @@
         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 @@
           {
           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 @@
           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 @@
         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 (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 (counts_printed != 0 && filenames >= FN_DEFAULT)
     fprintf(stdout, "TOTAL:");
-  fprintf(stdout, "%d" STDOUT_NL, total_count);
+  fprintf(stdout, "%lu" STDOUT_NL, total_count);
   }


EXIT: