summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorJim Meyering <jim@meyering.net>1993-01-20 04:29:09 +0000
committerJim Meyering <jim@meyering.net>1993-01-20 04:29:09 +0000
commitb53876554779e7778b84f11abc65a5fbcf5e3971 (patch)
treee2e36d9eb8c4cb55c8d5f702c6693445b0ba9ef1 /lib
parentadd6b20a4df42e902c2c708ff6d7b9b7ae949d0e (diff)
downloadcoreutils-b53876554779e7778b84f11abc65a5fbcf5e3971.tar.xz
merge with 1.4
Diffstat (limited to 'lib')
-rw-r--r--lib/regex.c57
1 files changed, 30 insertions, 27 deletions
diff --git a/lib/regex.c b/lib/regex.c
index a0e4e8950..eda11b535 100644
--- a/lib/regex.c
+++ b/lib/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 <sys/types.h>
-#if defined (HAVE_CONFIG_H) || defined (emacs)
+#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
@@ -2197,18 +2197,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. */
@@ -3989,21 +3991,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 +4869,18 @@ 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_size = strlen (msg) + 1; /* Includes the null. */
if (errbuf_size != 0)
{