X-Git-Url: http://erislabs.net/gitweb/?a=blobdiff_plain;f=regex.c;h=4d617d39b172b9f065fb08a3ef20333c8e3671fc;hb=a9576d3cabf1bfe37c4a886666696757d79e6a47;hp=a0e4e8950e56dae0ce34fc0b5b128a9ea3bcec10;hpb=e1c6111c70d52db5c0085096cbde7859ce8000ba;p=gnulib.git diff --git a/regex.c b/regex.c index a0e4e8950..4d617d39b 100644 --- a/regex.c +++ b/regex.c @@ -3,7 +3,7 @@ (Implements POSIX draft P10003.2/D11.2, except for internationalization features.) - Copyright (C) 1985, 89, 90, 91, 92 Free Software Foundation, Inc. + Copyright (C) 1993 Free Software Foundation, Inc. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -29,7 +29,7 @@ /* We need this for `regex.h', and perhaps for the Emacs include files. */ #include -#if defined (HAVE_CONFIG_H) || defined (emacs) +#ifdef HAVE_CONFIG_H #include "config.h" #endif @@ -1302,6 +1302,7 @@ regex_compile (pattern, size, syntax, bufp) the `*'. Do we have to do something analogous here for null bytes, because of RE_DOT_NOT_NULL? */ if (TRANSLATE (*(p - 2)) == TRANSLATE ('.') + && zero_times_ok && p < pend && TRANSLATE (*p) == TRANSLATE ('\n') && !(syntax & RE_DOT_NEWLINE)) { /* We have .*\n. */ @@ -1612,6 +1613,10 @@ regex_compile (pattern, size, syntax, bufp) fixup_alt_jump = 0; laststart = 0; begalt = b; + /* If we've reached MAX_REGNUM groups, then this open + won't actually generate any code, so we'll have to + clear pending_exact explicitly. */ + pending_exact = 0; break; @@ -1661,6 +1666,10 @@ regex_compile (pattern, size, syntax, bufp) : 0; laststart = bufp->buffer + COMPILE_STACK_TOP.laststart_offset; this_group_regnum = COMPILE_STACK_TOP.regnum; + /* If we've reached MAX_REGNUM groups, then this open + won't actually generate any code, so we'll have to + clear pending_exact explicitly. */ + pending_exact = 0; /* We're at the end of the group, so now we know how many groups were inside this one. */ @@ -2197,18 +2206,20 @@ compile_range (p_ptr, pend, translate, syntax, b) unsigned this_char; const char *p = *p_ptr; + int range_start, range_end; - /* Even though the pattern is a signed `char *', we need to fetch into - `unsigned char's. Reason: if the high bit of the pattern character - is set, the range endpoints will be negative if we fetch into a - signed `char *'. */ - unsigned char range_end; - unsigned char range_start = p[-2]; - if (p == pend) return REG_ERANGE; - PATFETCH (range_end); + /* Even though the pattern is a signed `char *', we need to fetch + with unsigned char *'s; if the high bit of the pattern character + is set, the range endpoints will be negative if we fetch using a + signed char *. + + We also want to fetch the endpoints without translating them; the + appropriate translation is done in the bit-setting loop below. */ + range_start = ((unsigned char *) p)[-2]; + range_end = ((unsigned char *) p)[0]; /* Have to increment the pointer into the pattern string, so the caller isn't still at the ending character. */ @@ -2928,7 +2939,8 @@ re_search_2 (bufp, string1, size1, string2, size2, startpos, range, regs, stop) inside the loop. */ if (translate) while (range > lim - && !fastmap[(unsigned char) translate[*d++]]) + && !fastmap[(unsigned char) + translate[(unsigned char) *d++]]) range--; else while (range > lim && !fastmap[(unsigned char) *d++]) @@ -3989,21 +4001,13 @@ re_match_2 (bufp, string1, size1, string2, size2, pos, regs, stop) /* If we're at the end of the pattern, we can change. */ if (p2 == pend) - { /* But if we're also at the end of the string, we might - as well skip changing anything. For example, in `a+' - against `a', we'll have already matched the `a', and - I don't see the the point of changing the opcode, - popping the failure point, finding out it fails, and - then going into our endgame. */ - if (d == dend) - { - p = pend; - DEBUG_PRINT1 (" End of pattern & string => done.\n"); - continue; - } - + { + /* Consider what happens when matching ":\(.*\)" + against ":/". I don't really understand this code + yet. */ p[-3] = (unsigned char) pop_failure_jump; - DEBUG_PRINT1 (" End of pattern => pop_failure_jump.\n"); + DEBUG_PRINT1 + (" End of pattern: change to `pop_failure_jump'.\n"); } else if ((re_opcode_t) *p2 == exactn @@ -4875,9 +4879,25 @@ regerror (errcode, preg, errbuf, errbuf_size) char *errbuf; size_t errbuf_size; { - const char *msg - = re_error_msg[errcode] == NULL ? "Success" : re_error_msg[errcode]; - size_t msg_size = strlen (msg) + 1; /* Includes the null. */ + const char *msg; + size_t msg_size; + + if (errcode < 0 + || errcode >= (sizeof (re_error_msg) / sizeof (re_error_msg[0]))) + /* Only error codes returned by the rest of the code should be passed + to this routine. If we are given anything else, or if other regex + code generates an invalid error code, then the program has a bug. + Dump core so we can fix it. */ + abort (); + + msg = re_error_msg[errcode]; + + /* POSIX doesn't require that we do anything in this case, but why + not be nice. */ + if (! msg) + msg = "Success"; + + msg_size = strlen (msg) + 1; /* Includes the null. */ if (errbuf_size != 0) {