aboutsummaryrefslogtreecommitdiffstats
path: root/re.c
diff options
context:
space:
mode:
Diffstat (limited to 're.c')
-rw-r--r--re.c19
1 files changed, 16 insertions, 3 deletions
diff --git a/re.c b/re.c
index c0d2e90e..b67a02fa 100644
--- a/re.c
+++ b/re.c
@@ -75,10 +75,10 @@ make_regexp(const char *s, size_t len, bool ignorecase, bool dfa, bool canfatal)
* from that.
*/
if (buf == NULL) {
- emalloc(buf, char *, len + 2, "make_regexp");
+ emalloc(buf, char *, len + 1, "make_regexp");
buflen = len;
} else if (len > buflen) {
- erealloc(buf, char *, len + 2, "make_regexp");
+ erealloc(buf, char *, len + 1, "make_regexp");
buflen = len;
}
dest = buf;
@@ -351,10 +351,14 @@ re_update(NODE *t)
/* regex was compiled with settings matching IGNORECASE */
if ((t->re_flags & CONSTANT) != 0) {
/* it's a constant, so just return it as is */
- assert(t->type == Node_regex);
+ assert(t->type == Node_regex || t->type == Node_typedregex);
return t->re_reg;
}
t1 = t->re_exp;
+ if (t1->type == Node_typedregex) {
+ assert((t1->re_flags & CONSTANT) != 0);
+ return t1->re_reg;
+ }
if (t->re_text != NULL) {
/* if contents haven't changed, just return it */
if (cmp_nodes(t->re_text, t1) == 0)
@@ -429,6 +433,15 @@ avoid_dfa(NODE *re, char *str, size_t len)
{
char *end;
+ /*
+ * f = @/.../
+ * if ("foo" ~ f) ...
+ *
+ * This creates a Node_dynregex with NULL re_reg.
+ */
+ if (re->re_reg == NULL)
+ return false;
+
if (! re->re_reg->has_anchor)
return false;