summaryrefslogtreecommitdiff
path: root/src/regex.c
diff options
context:
space:
mode:
authorRichard M. Stallman <rms@gnu.org>1994-07-01 06:19:16 +0000
committerRichard M. Stallman <rms@gnu.org>1994-07-01 06:19:16 +0000
commiteb016f00d7b93114da2444bc463d4d5c9af012ed (patch)
treebf88ebae5267a043918ab05f442969fc97b9bcc1 /src/regex.c
parentbac941922182943b0e004ed379cf4a22886445e3 (diff)
downloademacs-eb016f00d7b93114da2444bc463d4d5c9af012ed.tar.gz
entered into RCS
Diffstat (limited to 'src/regex.c')
-rw-r--r--src/regex.c54
1 files changed, 32 insertions, 22 deletions
diff --git a/src/regex.c b/src/regex.c
index 9e7145d2f63..fb829770c54 100644
--- a/src/regex.c
+++ b/src/regex.c
@@ -1490,6 +1490,15 @@ typedef struct
The `fastmap' and `newline_anchor' fields are neither
examined nor set. */
+/* Return, freeing storage we allocated. */
+#define FREE_STACK_RETURN(value) \
+do \
+{ \
+ free (compile_stack.stack); \
+ return value; \
+} \
+while (1)
+
static reg_errcode_t
regex_compile (pattern, size, syntax, bufp)
const char *pattern;
@@ -1596,7 +1605,7 @@ regex_compile (pattern, size, syntax, bufp)
{ /* Caller did not allocate a buffer. Do it for them. */
bufp->buffer = TALLOC (INIT_BUF_SIZE, unsigned char);
}
- if (!bufp->buffer) return REG_ESPACE;
+ if (!bufp->buffer) FREE_STACK_RETURN (REG_ESPACE);
bufp->allocated = INIT_BUF_SIZE;
}
@@ -1651,7 +1660,7 @@ regex_compile (pattern, size, syntax, bufp)
if (!laststart)
{
if (syntax & RE_CONTEXT_INVALID_OPS)
- return REG_BADRPT;
+ FREE_STACK_RETURN (REG_BADRPT);
else if (!(syntax & RE_CONTEXT_INDEP_OPS))
goto normal_char;
}
@@ -1684,7 +1693,7 @@ regex_compile (pattern, size, syntax, bufp)
else if (syntax & RE_BK_PLUS_QM && c == '\\')
{
- if (p == pend) return REG_EESCAPE;
+ if (p == pend) FREE_STACK_RETURN (REG_EESCAPE);
PATFETCH (c1);
if (!(c1 == '+' || c1 == '?'))
@@ -1783,7 +1792,7 @@ regex_compile (pattern, size, syntax, bufp)
{
boolean had_char_class = false;
- if (p == pend) return REG_EBRACK;
+ if (p == pend) FREE_STACK_RETURN (REG_EBRACK);
/* Ensure that we have enough space to push a charset: the
opcode, the length count, and the bitset; 34 bytes in all. */
@@ -1814,14 +1823,14 @@ regex_compile (pattern, size, syntax, bufp)
/* Read in characters and ranges, setting map bits. */
for (;;)
{
- if (p == pend) return REG_EBRACK;
+ if (p == pend) FREE_STACK_RETURN (REG_EBRACK);
PATFETCH (c);
/* \ might escape characters inside [...] and [^...]. */
if ((syntax & RE_BACKSLASH_ESCAPE_IN_LISTS) && c == '\\')
{
- if (p == pend) return REG_EESCAPE;
+ if (p == pend) FREE_STACK_RETURN (REG_EESCAPE);
PATFETCH (c1);
SET_LIST_BIT (c1);
@@ -1837,7 +1846,7 @@ regex_compile (pattern, size, syntax, bufp)
/* Look ahead to see if it's a range when the last thing
was a character class. */
if (had_char_class && c == '-' && *p != ']')
- return REG_ERANGE;
+ FREE_STACK_RETURN (REG_ERANGE);
/* Look ahead to see if it's a range when the last thing
was a character: if this is a hyphen not at the
@@ -1850,7 +1859,7 @@ regex_compile (pattern, size, syntax, bufp)
{
reg_errcode_t ret
= compile_range (&p, pend, translate, syntax, b);
- if (ret != REG_NOERROR) return ret;
+ if (ret != REG_NOERROR) FREE_STACK_RETURN (ret);
}
else if (p[0] == '-' && p[1] != ']')
@@ -1861,7 +1870,7 @@ regex_compile (pattern, size, syntax, bufp)
PATFETCH (c1);
ret = compile_range (&p, pend, translate, syntax, b);
- if (ret != REG_NOERROR) return ret;
+ if (ret != REG_NOERROR) FREE_STACK_RETURN (ret);
}
/* See if we're at the beginning of a possible character
@@ -1875,7 +1884,7 @@ regex_compile (pattern, size, syntax, bufp)
c1 = 0;
/* If pattern is `[[:'. */
- if (p == pend) return REG_EBRACK;
+ if (p == pend) FREE_STACK_RETURN (REG_EBRACK);
for (;;)
{
@@ -1906,13 +1915,14 @@ regex_compile (pattern, size, syntax, bufp)
boolean is_upper = STREQ (str, "upper");
boolean is_xdigit = STREQ (str, "xdigit");
- if (!IS_CHAR_CLASS (str)) return REG_ECTYPE;
+ if (!IS_CHAR_CLASS (str))
+ FREE_STACK_RETURN (REG_ECTYPE);
/* Throw away the ] at the end of the character
class. */
PATFETCH (c);
- if (p == pend) return REG_EBRACK;
+ if (p == pend) FREE_STACK_RETURN (REG_EBRACK);
for (ch = 0; ch < 1 << BYTEWIDTH; ch++)
{
@@ -1994,7 +2004,7 @@ regex_compile (pattern, size, syntax, bufp)
case '\\':
- if (p == pend) return REG_EESCAPE;
+ if (p == pend) FREE_STACK_RETURN (REG_EESCAPE);
/* Do not translate the character after the \, so that we can
distinguish, e.g., \B from \b, even if we normally would
@@ -2059,7 +2069,7 @@ regex_compile (pattern, size, syntax, bufp)
if (syntax & RE_UNMATCHED_RIGHT_PAREN_ORD)
goto normal_backslash;
else
- return REG_ERPAREN;
+ FREE_STACK_RETURN (REG_ERPAREN);
handle_close:
if (fixup_alt_jump)
@@ -2079,7 +2089,7 @@ regex_compile (pattern, size, syntax, bufp)
if (syntax & RE_UNMATCHED_RIGHT_PAREN_ORD)
goto normal_char;
else
- return REG_ERPAREN;
+ FREE_STACK_RETURN (REG_ERPAREN);
/* Since we just checked for an empty stack above, this
``can't happen''. */
@@ -2186,7 +2196,7 @@ regex_compile (pattern, size, syntax, bufp)
if (syntax & RE_NO_BK_BRACES)
goto unfetch_interval;
else
- return REG_EBRACE;
+ FREE_STACK_RETURN (REG_EBRACE);
}
GET_UNSIGNED_NUMBER (lower_bound);
@@ -2206,12 +2216,12 @@ regex_compile (pattern, size, syntax, bufp)
if (syntax & RE_NO_BK_BRACES)
goto unfetch_interval;
else
- return REG_BADBR;
+ FREE_STACK_RETURN (REG_BADBR);
}
if (!(syntax & RE_NO_BK_BRACES))
{
- if (c != '\\') return REG_EBRACE;
+ if (c != '\\') FREE_STACK_RETURN (REG_EBRACE);
PATFETCH (c);
}
@@ -2221,7 +2231,7 @@ regex_compile (pattern, size, syntax, bufp)
if (syntax & RE_NO_BK_BRACES)
goto unfetch_interval;
else
- return REG_BADBR;
+ FREE_STACK_RETURN (REG_BADBR);
}
/* We just parsed a valid interval. */
@@ -2230,7 +2240,7 @@ regex_compile (pattern, size, syntax, bufp)
if (!laststart)
{
if (syntax & RE_CONTEXT_INVALID_OPS)
- return REG_BADRPT;
+ FREE_STACK_RETURN (REG_BADRPT);
else if (syntax & RE_CONTEXT_INDEP_OPS)
laststart = b;
else
@@ -2397,7 +2407,7 @@ regex_compile (pattern, size, syntax, bufp)
c1 = c - '0';
if (c1 > regnum)
- return REG_ESUBREG;
+ FREE_STACK_RETURN (REG_ESUBREG);
/* Can't back reference to a subexpression if inside of it. */
if (group_in_compile_stack (compile_stack, c1))
@@ -2469,7 +2479,7 @@ regex_compile (pattern, size, syntax, bufp)
STORE_JUMP (jump_past_alt, fixup_alt_jump, b);
if (!COMPILE_STACK_EMPTY)
- return REG_EPAREN;
+ FREE_STACK_RETURN (REG_EPAREN);
free (compile_stack.stack);