summaryrefslogtreecommitdiff
path: root/editors/awk.c
diff options
context:
space:
mode:
authorDenis Vlasenko2009-03-15 22:20:31 +0000
committerDenis Vlasenko2009-03-15 22:20:31 +0000
commit7a6766428e3306c3bdc98e0fff207e5015af8930 (patch)
treeae7fee824a19d909c91cec0e2000551eb9d64d81 /editors/awk.c
parent9210a36495f90343989a7cd90b2c1949803c7460 (diff)
downloadbusybox-7a6766428e3306c3bdc98e0fff207e5015af8930.zip
busybox-7a6766428e3306c3bdc98e0fff207e5015af8930.tar.gz
awk: fix compat issue found by gpm build
function old new delta as_regex 105 131 +26 hash_find 247 233 -14 ------------------------------------------------------------------------------ (add/remove: 0/0 grow/shrink: 1/1 up/down: 26/-14) Total: 12 bytes
Diffstat (limited to 'editors/awk.c')
-rw-r--r--editors/awk.c17
1 files changed, 14 insertions, 3 deletions
diff --git a/editors/awk.c b/editors/awk.c
index 3f8368c..9b15b3c 100644
--- a/editors/awk.c
+++ b/editors/awk.c
@@ -604,8 +604,8 @@ static void *hash_find(xhash *hash, const char *name)
hash_rebuild(hash);
l = strlen(name) + 1;
- hi = xzalloc(sizeof(hash_item) + l);
- memcpy(hi->name, name, l);
+ hi = xzalloc(sizeof(*hi) + l);
+ strcpy(hi->name, name);
idx = hashidx(name) % hash->csize;
hi->next = hash->items[idx];
@@ -1482,6 +1482,7 @@ static node *mk_splitter(const char *s, tsplitter *spl)
*/
static regex_t *as_regex(node *op, regex_t *preg)
{
+ int cflags;
var *v;
const char *s;
@@ -1490,7 +1491,17 @@ static regex_t *as_regex(node *op, regex_t *preg)
}
v = nvalloc(1);
s = getvar_s(evaluate(op, v));
- xregcomp(preg, s, icase ? REG_EXTENDED | REG_ICASE : REG_EXTENDED);
+
+ cflags = icase ? REG_EXTENDED | REG_ICASE : REG_EXTENDED;
+ /* Testcase where REG_EXTENDED fails (unpaired '{'):
+ * echo Hi | awk 'gsub("@(samp|code|file)\{","");'
+ * gawk 3.1.5 eats this. We revert to ~REG_EXTENDED
+ * (maybe gsub is not supposed to use REG_EXTENDED?).
+ */
+ if (regcomp(preg, s, cflags)) {
+ cflags &= ~REG_EXTENDED;
+ xregcomp(preg, s, cflags);
+ }
nvfree(v);
return preg;
}