aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorRichard M. Stallman1994-07-01 06:19:16 +0000
committerRichard M. Stallman1994-07-01 06:19:16 +0000
commit69c38b460f3815a40a16d49d40458f5685b43b4d (patch)
tree135a0c59ed68f33ac7bd34e288cd63265f9f6f63 /src
parent118bd8410d176d21bb86722958ce87b509829aef (diff)
downloademacs-69c38b460f3815a40a16d49d40458f5685b43b4d.tar.gz
emacs-69c38b460f3815a40a16d49d40458f5685b43b4d.zip
entered into RCS
Diffstat (limited to 'src')
-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
1490 The `fastmap' and `newline_anchor' fields are neither 1490 The `fastmap' and `newline_anchor' fields are neither
1491 examined nor set. */ 1491 examined nor set. */
1492 1492
1493/* Return, freeing storage we allocated. */
1494#define FREE_STACK_RETURN(value) \
1495do \
1496{ \
1497 free (compile_stack.stack); \
1498 return value; \
1499} \
1500while (1)
1501
1493static reg_errcode_t 1502static reg_errcode_t
1494regex_compile (pattern, size, syntax, bufp) 1503regex_compile (pattern, size, syntax, bufp)
1495 const char *pattern; 1504 const char *pattern;
@@ -1596,7 +1605,7 @@ regex_compile (pattern, size, syntax, bufp)
1596 { /* Caller did not allocate a buffer. Do it for them. */ 1605 { /* Caller did not allocate a buffer. Do it for them. */
1597 bufp->buffer = TALLOC (INIT_BUF_SIZE, unsigned char); 1606 bufp->buffer = TALLOC (INIT_BUF_SIZE, unsigned char);
1598 } 1607 }
1599 if (!bufp->buffer) return REG_ESPACE; 1608 if (!bufp->buffer) FREE_STACK_RETURN (REG_ESPACE);
1600 1609
1601 bufp->allocated = INIT_BUF_SIZE; 1610 bufp->allocated = INIT_BUF_SIZE;
1602 } 1611 }
@@ -1651,7 +1660,7 @@ regex_compile (pattern, size, syntax, bufp)
1651 if (!laststart) 1660 if (!laststart)
1652 { 1661 {
1653 if (syntax & RE_CONTEXT_INVALID_OPS) 1662 if (syntax & RE_CONTEXT_INVALID_OPS)
1654 return REG_BADRPT; 1663 FREE_STACK_RETURN (REG_BADRPT);
1655 else if (!(syntax & RE_CONTEXT_INDEP_OPS)) 1664 else if (!(syntax & RE_CONTEXT_INDEP_OPS))
1656 goto normal_char; 1665 goto normal_char;
1657 } 1666 }
@@ -1684,7 +1693,7 @@ regex_compile (pattern, size, syntax, bufp)
1684 1693
1685 else if (syntax & RE_BK_PLUS_QM && c == '\\') 1694 else if (syntax & RE_BK_PLUS_QM && c == '\\')
1686 { 1695 {
1687 if (p == pend) return REG_EESCAPE; 1696 if (p == pend) FREE_STACK_RETURN (REG_EESCAPE);
1688 1697
1689 PATFETCH (c1); 1698 PATFETCH (c1);
1690 if (!(c1 == '+' || c1 == '?')) 1699 if (!(c1 == '+' || c1 == '?'))
@@ -1783,7 +1792,7 @@ regex_compile (pattern, size, syntax, bufp)
1783 { 1792 {
1784 boolean had_char_class = false; 1793 boolean had_char_class = false;
1785 1794
1786 if (p == pend) return REG_EBRACK; 1795 if (p == pend) FREE_STACK_RETURN (REG_EBRACK);
1787 1796
1788 /* Ensure that we have enough space to push a charset: the 1797 /* Ensure that we have enough space to push a charset: the
1789 opcode, the length count, and the bitset; 34 bytes in all. */ 1798 opcode, the length count, and the bitset; 34 bytes in all. */
@@ -1814,14 +1823,14 @@ regex_compile (pattern, size, syntax, bufp)
1814 /* Read in characters and ranges, setting map bits. */ 1823 /* Read in characters and ranges, setting map bits. */
1815 for (;;) 1824 for (;;)
1816 { 1825 {
1817 if (p == pend) return REG_EBRACK; 1826 if (p == pend) FREE_STACK_RETURN (REG_EBRACK);
1818 1827
1819 PATFETCH (c); 1828 PATFETCH (c);
1820 1829
1821 /* \ might escape characters inside [...] and [^...]. */ 1830 /* \ might escape characters inside [...] and [^...]. */
1822 if ((syntax & RE_BACKSLASH_ESCAPE_IN_LISTS) && c == '\\') 1831 if ((syntax & RE_BACKSLASH_ESCAPE_IN_LISTS) && c == '\\')
1823 { 1832 {
1824 if (p == pend) return REG_EESCAPE; 1833 if (p == pend) FREE_STACK_RETURN (REG_EESCAPE);
1825 1834
1826 PATFETCH (c1); 1835 PATFETCH (c1);
1827 SET_LIST_BIT (c1); 1836 SET_LIST_BIT (c1);
@@ -1837,7 +1846,7 @@ regex_compile (pattern, size, syntax, bufp)
1837 /* Look ahead to see if it's a range when the last thing 1846 /* Look ahead to see if it's a range when the last thing
1838 was a character class. */ 1847 was a character class. */
1839 if (had_char_class && c == '-' && *p != ']') 1848 if (had_char_class && c == '-' && *p != ']')
1840 return REG_ERANGE; 1849 FREE_STACK_RETURN (REG_ERANGE);
1841 1850
1842 /* Look ahead to see if it's a range when the last thing 1851 /* Look ahead to see if it's a range when the last thing
1843 was a character: if this is a hyphen not at the 1852 was a character: if this is a hyphen not at the
@@ -1850,7 +1859,7 @@ regex_compile (pattern, size, syntax, bufp)
1850 { 1859 {
1851 reg_errcode_t ret 1860 reg_errcode_t ret
1852 = compile_range (&p, pend, translate, syntax, b); 1861 = compile_range (&p, pend, translate, syntax, b);
1853 if (ret != REG_NOERROR) return ret; 1862 if (ret != REG_NOERROR) FREE_STACK_RETURN (ret);
1854 } 1863 }
1855 1864
1856 else if (p[0] == '-' && p[1] != ']') 1865 else if (p[0] == '-' && p[1] != ']')
@@ -1861,7 +1870,7 @@ regex_compile (pattern, size, syntax, bufp)
1861 PATFETCH (c1); 1870 PATFETCH (c1);
1862 1871
1863 ret = compile_range (&p, pend, translate, syntax, b); 1872 ret = compile_range (&p, pend, translate, syntax, b);
1864 if (ret != REG_NOERROR) return ret; 1873 if (ret != REG_NOERROR) FREE_STACK_RETURN (ret);
1865 } 1874 }
1866 1875
1867 /* See if we're at the beginning of a possible character 1876 /* See if we're at the beginning of a possible character
@@ -1875,7 +1884,7 @@ regex_compile (pattern, size, syntax, bufp)
1875 c1 = 0; 1884 c1 = 0;
1876 1885
1877 /* If pattern is `[[:'. */ 1886 /* If pattern is `[[:'. */
1878 if (p == pend) return REG_EBRACK; 1887 if (p == pend) FREE_STACK_RETURN (REG_EBRACK);
1879 1888
1880 for (;;) 1889 for (;;)
1881 { 1890 {
@@ -1906,13 +1915,14 @@ regex_compile (pattern, size, syntax, bufp)
1906 boolean is_upper = STREQ (str, "upper"); 1915 boolean is_upper = STREQ (str, "upper");
1907 boolean is_xdigit = STREQ (str, "xdigit"); 1916 boolean is_xdigit = STREQ (str, "xdigit");
1908 1917
1909 if (!IS_CHAR_CLASS (str)) return REG_ECTYPE; 1918 if (!IS_CHAR_CLASS (str))
1919 FREE_STACK_RETURN (REG_ECTYPE);
1910 1920
1911 /* Throw away the ] at the end of the character 1921 /* Throw away the ] at the end of the character
1912 class. */ 1922 class. */
1913 PATFETCH (c); 1923 PATFETCH (c);
1914 1924
1915 if (p == pend) return REG_EBRACK; 1925 if (p == pend) FREE_STACK_RETURN (REG_EBRACK);
1916 1926
1917 for (ch = 0; ch < 1 << BYTEWIDTH; ch++) 1927 for (ch = 0; ch < 1 << BYTEWIDTH; ch++)
1918 { 1928 {
@@ -1994,7 +2004,7 @@ regex_compile (pattern, size, syntax, bufp)
1994 2004
1995 2005
1996 case '\\': 2006 case '\\':
1997 if (p == pend) return REG_EESCAPE; 2007 if (p == pend) FREE_STACK_RETURN (REG_EESCAPE);
1998 2008
1999 /* Do not translate the character after the \, so that we can 2009 /* Do not translate the character after the \, so that we can
2000 distinguish, e.g., \B from \b, even if we normally would 2010 distinguish, e.g., \B from \b, even if we normally would
@@ -2059,7 +2069,7 @@ regex_compile (pattern, size, syntax, bufp)
2059 if (syntax & RE_UNMATCHED_RIGHT_PAREN_ORD) 2069 if (syntax & RE_UNMATCHED_RIGHT_PAREN_ORD)
2060 goto normal_backslash; 2070 goto normal_backslash;
2061 else 2071 else
2062 return REG_ERPAREN; 2072 FREE_STACK_RETURN (REG_ERPAREN);
2063 2073
2064 handle_close: 2074 handle_close:
2065 if (fixup_alt_jump) 2075 if (fixup_alt_jump)
@@ -2079,7 +2089,7 @@ regex_compile (pattern, size, syntax, bufp)
2079 if (syntax & RE_UNMATCHED_RIGHT_PAREN_ORD) 2089 if (syntax & RE_UNMATCHED_RIGHT_PAREN_ORD)
2080 goto normal_char; 2090 goto normal_char;
2081 else 2091 else
2082 return REG_ERPAREN; 2092 FREE_STACK_RETURN (REG_ERPAREN);
2083 2093
2084 /* Since we just checked for an empty stack above, this 2094 /* Since we just checked for an empty stack above, this
2085 ``can't happen''. */ 2095 ``can't happen''. */
@@ -2186,7 +2196,7 @@ regex_compile (pattern, size, syntax, bufp)
2186 if (syntax & RE_NO_BK_BRACES) 2196 if (syntax & RE_NO_BK_BRACES)
2187 goto unfetch_interval; 2197 goto unfetch_interval;
2188 else 2198 else
2189 return REG_EBRACE; 2199 FREE_STACK_RETURN (REG_EBRACE);
2190 } 2200 }
2191 2201
2192 GET_UNSIGNED_NUMBER (lower_bound); 2202 GET_UNSIGNED_NUMBER (lower_bound);
@@ -2206,12 +2216,12 @@ regex_compile (pattern, size, syntax, bufp)
2206 if (syntax & RE_NO_BK_BRACES) 2216 if (syntax & RE_NO_BK_BRACES)
2207 goto unfetch_interval; 2217 goto unfetch_interval;
2208 else 2218 else
2209 return REG_BADBR; 2219 FREE_STACK_RETURN (REG_BADBR);
2210 } 2220 }
2211 2221
2212 if (!(syntax & RE_NO_BK_BRACES)) 2222 if (!(syntax & RE_NO_BK_BRACES))
2213 { 2223 {
2214 if (c != '\\') return REG_EBRACE; 2224 if (c != '\\') FREE_STACK_RETURN (REG_EBRACE);
2215 2225
2216 PATFETCH (c); 2226 PATFETCH (c);
2217 } 2227 }
@@ -2221,7 +2231,7 @@ regex_compile (pattern, size, syntax, bufp)
2221 if (syntax & RE_NO_BK_BRACES) 2231 if (syntax & RE_NO_BK_BRACES)
2222 goto unfetch_interval; 2232 goto unfetch_interval;
2223 else 2233 else
2224 return REG_BADBR; 2234 FREE_STACK_RETURN (REG_BADBR);
2225 } 2235 }
2226 2236
2227 /* We just parsed a valid interval. */ 2237 /* We just parsed a valid interval. */
@@ -2230,7 +2240,7 @@ regex_compile (pattern, size, syntax, bufp)
2230 if (!laststart) 2240 if (!laststart)
2231 { 2241 {
2232 if (syntax & RE_CONTEXT_INVALID_OPS) 2242 if (syntax & RE_CONTEXT_INVALID_OPS)
2233 return REG_BADRPT; 2243 FREE_STACK_RETURN (REG_BADRPT);
2234 else if (syntax & RE_CONTEXT_INDEP_OPS) 2244 else if (syntax & RE_CONTEXT_INDEP_OPS)
2235 laststart = b; 2245 laststart = b;
2236 else 2246 else
@@ -2397,7 +2407,7 @@ regex_compile (pattern, size, syntax, bufp)
2397 c1 = c - '0'; 2407 c1 = c - '0';
2398 2408
2399 if (c1 > regnum) 2409 if (c1 > regnum)
2400 return REG_ESUBREG; 2410 FREE_STACK_RETURN (REG_ESUBREG);
2401 2411
2402 /* Can't back reference to a subexpression if inside of it. */ 2412 /* Can't back reference to a subexpression if inside of it. */
2403 if (group_in_compile_stack (compile_stack, c1)) 2413 if (group_in_compile_stack (compile_stack, c1))
@@ -2469,7 +2479,7 @@ regex_compile (pattern, size, syntax, bufp)
2469 STORE_JUMP (jump_past_alt, fixup_alt_jump, b); 2479 STORE_JUMP (jump_past_alt, fixup_alt_jump, b);
2470 2480
2471 if (!COMPILE_STACK_EMPTY) 2481 if (!COMPILE_STACK_EMPTY)
2472 return REG_EPAREN; 2482 FREE_STACK_RETURN (REG_EPAREN);
2473 2483
2474 free (compile_stack.stack); 2484 free (compile_stack.stack);
2475 2485