diff options
author | Denis Vlasenko <vda.linux@googlemail.com> | 2009-03-15 22:20:31 +0000 |
---|---|---|
committer | Denis Vlasenko <vda.linux@googlemail.com> | 2009-03-15 22:20:31 +0000 |
commit | 7a6766428e3306c3bdc98e0fff207e5015af8930 (patch) | |
tree | ae7fee824a19d909c91cec0e2000551eb9d64d81 | |
parent | 9210a36495f90343989a7cd90b2c1949803c7460 (diff) | |
download | busybox-w32-7a6766428e3306c3bdc98e0fff207e5015af8930.tar.gz busybox-w32-7a6766428e3306c3bdc98e0fff207e5015af8930.tar.bz2 busybox-w32-7a6766428e3306c3bdc98e0fff207e5015af8930.zip |
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
-rw-r--r-- | editors/awk.c | 17 | ||||
-rwxr-xr-x | testsuite/awk.tests | 5 |
2 files changed, 19 insertions, 3 deletions
diff --git a/editors/awk.c b/editors/awk.c index 3f8368c8f..9b15b3cd6 100644 --- a/editors/awk.c +++ b/editors/awk.c | |||
@@ -604,8 +604,8 @@ static void *hash_find(xhash *hash, const char *name) | |||
604 | hash_rebuild(hash); | 604 | hash_rebuild(hash); |
605 | 605 | ||
606 | l = strlen(name) + 1; | 606 | l = strlen(name) + 1; |
607 | hi = xzalloc(sizeof(hash_item) + l); | 607 | hi = xzalloc(sizeof(*hi) + l); |
608 | memcpy(hi->name, name, l); | 608 | strcpy(hi->name, name); |
609 | 609 | ||
610 | idx = hashidx(name) % hash->csize; | 610 | idx = hashidx(name) % hash->csize; |
611 | hi->next = hash->items[idx]; | 611 | hi->next = hash->items[idx]; |
@@ -1482,6 +1482,7 @@ static node *mk_splitter(const char *s, tsplitter *spl) | |||
1482 | */ | 1482 | */ |
1483 | static regex_t *as_regex(node *op, regex_t *preg) | 1483 | static regex_t *as_regex(node *op, regex_t *preg) |
1484 | { | 1484 | { |
1485 | int cflags; | ||
1485 | var *v; | 1486 | var *v; |
1486 | const char *s; | 1487 | const char *s; |
1487 | 1488 | ||
@@ -1490,7 +1491,17 @@ static regex_t *as_regex(node *op, regex_t *preg) | |||
1490 | } | 1491 | } |
1491 | v = nvalloc(1); | 1492 | v = nvalloc(1); |
1492 | s = getvar_s(evaluate(op, v)); | 1493 | s = getvar_s(evaluate(op, v)); |
1493 | xregcomp(preg, s, icase ? REG_EXTENDED | REG_ICASE : REG_EXTENDED); | 1494 | |
1495 | cflags = icase ? REG_EXTENDED | REG_ICASE : REG_EXTENDED; | ||
1496 | /* Testcase where REG_EXTENDED fails (unpaired '{'): | ||
1497 | * echo Hi | awk 'gsub("@(samp|code|file)\{","");' | ||
1498 | * gawk 3.1.5 eats this. We revert to ~REG_EXTENDED | ||
1499 | * (maybe gsub is not supposed to use REG_EXTENDED?). | ||
1500 | */ | ||
1501 | if (regcomp(preg, s, cflags)) { | ||
1502 | cflags &= ~REG_EXTENDED; | ||
1503 | xregcomp(preg, s, cflags); | ||
1504 | } | ||
1494 | nvfree(v); | 1505 | nvfree(v); |
1495 | return preg; | 1506 | return preg; |
1496 | } | 1507 | } |
diff --git a/testsuite/awk.tests b/testsuite/awk.tests index 953a6e5e1..8e72dd38f 100755 --- a/testsuite/awk.tests +++ b/testsuite/awk.tests | |||
@@ -22,6 +22,11 @@ testing "awk hex const 1" "awk '{ print or(0xffffffff,1) }'" "4.29497e+09\n" "" | |||
22 | testing "awk hex const 2" "awk '{ print or(0x80000000,1) }'" "2.14748e+09\n" "" "\n" | 22 | testing "awk hex const 2" "awk '{ print or(0x80000000,1) }'" "2.14748e+09\n" "" "\n" |
23 | testing "awk oct const" "awk '{ print or(01234,1) }'" "669\n" "" "\n" | 23 | testing "awk oct const" "awk '{ print or(01234,1) }'" "669\n" "" "\n" |
24 | 24 | ||
25 | # '@(samp|code|file)\{' is an invalid extended regex (unmatched '{'), | ||
26 | # but gawk 3.1.5 does not bail out on it. | ||
27 | testing "awk gsub falls back to non-extended-regex" \ | ||
28 | "awk 'gsub(\"@(samp|code|file)\{\",\"\");'; echo \$?" "0\n" "" "Hi\n" | ||
29 | |||
25 | tar xjf awk_t1.tar.bz2 | 30 | tar xjf awk_t1.tar.bz2 |
26 | testing "awk 'gcc build bug'" \ | 31 | testing "awk 'gcc build bug'" \ |
27 | "awk -f awk_t1_opt-functions.awk -f awk_t1_opth-gen.awk <awk_t1_input | md5sum" \ | 32 | "awk -f awk_t1_opt-functions.awk -f awk_t1_opth-gen.awk <awk_t1_input | md5sum" \ |