diff options
Diffstat (limited to 'gcc/fixinc/gnu-regex.c')
-rw-r--r-- | gcc/fixinc/gnu-regex.c | 43 |
1 files changed, 27 insertions, 16 deletions
diff --git a/gcc/fixinc/gnu-regex.c b/gcc/fixinc/gnu-regex.c index b24845b..007aec1 100644 --- a/gcc/fixinc/gnu-regex.c +++ b/gcc/fixinc/gnu-regex.c @@ -21,11 +21,6 @@ along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ -/* AIX requires this to be the first thing in the file. */ -#if defined _AIX && !defined REGEX_MALLOC - #pragma alloca -#endif - #undef _GNU_SOURCE #define _GNU_SOURCE @@ -33,6 +28,16 @@ # include <config.h> #endif +/* Do not use a C alloca, we will leak memory and crash. */ +#ifdef C_ALLOCA +# define REGEX_MALLOC +#endif + +/* AIX requires this to be the first thing in the file. */ +#if defined _AIX && !defined REGEX_MALLOC + #pragma alloca +#endif + #ifndef PARAMS # if defined __GNUC__ || (defined __STDC__ && __STDC__) # define PARAMS(args) args @@ -153,11 +158,6 @@ char *realloc (); /* How many characters in the character set. */ # define CHAR_SET_SIZE 256 -/* GDB LOCAL: define _REGEX_RE_COMP to get BSD style re_comp and re_exec */ -#ifndef _REGEX_RE_COMP -#define _REGEX_RE_COMP -#endif - # ifdef SYNTAX_TABLE extern char *re_syntax_table; @@ -5561,7 +5561,8 @@ re_exec (s) REG_EXTENDED bit in CFLAGS is set; otherwise, to RE_SYNTAX_POSIX_BASIC; `newline_anchor' to REG_NEWLINE being set in CFLAGS; - `fastmap' and `fastmap_accurate' to zero; + `fastmap' to an allocated space for the fastmap; + `fastmap_accurate' to 1; `re_nsub' to the number of subexpressions in PATTERN. PATTERN is the address of the pattern string. @@ -5600,11 +5601,8 @@ regcomp (preg, pattern, cflags) preg->allocated = 0; preg->used = 0; - /* Don't bother to use a fastmap when searching. This simplifies the - REG_NEWLINE case: if we used a fastmap, we'd have to put all the - characters after newlines into the fastmap. This way, we just try - every character. */ - preg->fastmap = 0; + /* Try to allocate space for the fastmap. */ + preg->fastmap = (char *) malloc (1 << BYTEWIDTH); if (cflags & REG_ICASE) { @@ -5644,6 +5642,19 @@ regcomp (preg, pattern, cflags) unmatched close-group: both are REG_EPAREN. */ if (ret == REG_ERPAREN) ret = REG_EPAREN; + if (ret == REG_NOERROR && preg->fastmap) + { + /* Compute the fastmap now, since regexec cannot modify the pattern + buffer. */ + if (re_compile_fastmap (preg) == -2) + { + /* Some error occured while computing the fastmap, just forget + about it. */ + free (preg->fastmap); + preg->fastmap = NULL; + } + } + return (int) ret; } #ifdef _LIBC |