aboutsummaryrefslogtreecommitdiffstats
path: root/re.c
diff options
context:
space:
mode:
authorArnold D. Robbins <arnold@skeeve.com>2013-03-11 22:45:22 +0200
committerArnold D. Robbins <arnold@skeeve.com>2013-03-11 22:45:22 +0200
commita7c502a756732ec9a1773d6169376bb7b25f4308 (patch)
tree75dd7a168a4e695438fdc2ba4d5959fd24ff2217 /re.c
parent2b02c5c64a93608c347ffaa312d88d52f93888da (diff)
downloadegawk-a7c502a756732ec9a1773d6169376bb7b25f4308.tar.gz
egawk-a7c502a756732ec9a1773d6169376bb7b25f4308.tar.bz2
egawk-a7c502a756732ec9a1773d6169376bb7b25f4308.zip
Fix a bug with ] as real char in regexps.
Diffstat (limited to 're.c')
-rw-r--r--re.c18
1 files changed, 16 insertions, 2 deletions
diff --git a/re.c b/re.c
index 711b53e4..4c031777 100644
--- a/re.c
+++ b/re.c
@@ -564,8 +564,22 @@ again:
if (*sp == '[')
count++;
- else if (*sp == ']')
- count--;
+ /*
+ * ] as first char after open [ is skipped
+ * \] is skipped
+ * [^]] is skipped
+ */
+ if (*sp == ']' && sp > sp2) {
+ if (sp[-1] != '['
+ && sp[-1] != '\\')
+ ;
+ else if ((sp - sp2) >= 2
+ && sp[-1] == '^' && sp[-2] == '[')
+ ;
+ else
+ count--;
+ }
+
if (*sp == '-' && do_lint && ! range_warned && count == 1
&& sp[-1] != '[' && sp[1] != ']'
&& ! isdigit((unsigned char) sp[-1]) && ! isdigit((unsigned char) sp[1])