Mercurial > hg > octave-lyh > gnulib-hg
changeset 228:180784e51088
entered into RCS
author | Richard Stallman <rms@gnu.org> |
---|---|
date | Fri, 01 Jul 1994 06:19:16 +0000 |
parents | a658d0ce4347 |
children | a15bea0a0d8c |
files | regex.c |
diffstat | 1 files changed, 32 insertions(+), 22 deletions(-) [+] |
line wrap: on
line diff
--- a/regex.c +++ b/regex.c @@ -1490,6 +1490,15 @@ 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 @@ { /* 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 @@ 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 @@ 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 @@ { 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 @@ /* 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 @@ /* 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 @@ { 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 @@ 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 @@ c1 = 0; /* If pattern is `[[:'. */ - if (p == pend) return REG_EBRACK; + if (p == pend) FREE_STACK_RETURN (REG_EBRACK); for (;;) { @@ -1906,13 +1915,14 @@ 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 @@ 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 @@ 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 @@ 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 @@ 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 @@ 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 @@ 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 @@ 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 @@ 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 @@ 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);