Re: [pcre-dev] Very large value for re_nsub

Top Page
Delete this message
Author: Philip Hazel
Date:  
To: Patrick Häcker
CC: pcre-dev
Subject: Re: [pcre-dev] Very large value for re_nsub
On Sat, 1 Sep 2012, Patrick Häcker wrote:

> Dear developers,
>
> when compiling the regular expression
>
> regex_t rx;
> regcomp(&rx, "^(\\(\\))? *(.*)$", 0)
>
> I get the large value 140733193388034 for rx.re_nsub (Debian, version 8.30).
> In the program at hand
> (http://www.stefant.org/web/projects/software/pplatex.html, regex.cpp, line
> 26), this value is used afterwards in malloc, which fails.
>
> Is such a high value normal? Is there some usage error?


I have very recently fixed a bug that may be the cause of your problem.
The patch is very small, so I'll copy it below. The bug affects systems
where size_t is not the same as int. Are you using a 64-bit system?

Philip

--
Philip Hazel


--- /home/ph10/tmp/pcre-8.31/pcreposix.c    2012-06-20 16:08:49.000000000 +0100
+++ pcreposix.c 2012-08-29 12:02:51.000000000 +0100
@@ -259,6 +259,7 @@
 int erroffset;
 int errorcode;
 int options = 0;
+int re_nsub = 0;


 if ((cflags & REG_ICASE) != 0)    options |= PCRE_CASELESS;
 if ((cflags & REG_NEWLINE) != 0)  options |= PCRE_MULTILINE;
@@ -282,7 +283,8 @@
   }


(void)pcre_fullinfo((const pcre *)preg->re_pcre, NULL, PCRE_INFO_CAPTURECOUNT,
- &(preg->re_nsub));
+ &re_nsub);
+preg->re_nsub = (size_t)re_nsub;
return 0;
}