diff options
author | Bernhard Reutner-Fischer <rep.dot.nop@gmail.com> | 2013-07-31 15:29:20 +0200 |
---|---|---|
committer | Bernhard Reutner-Fischer <rep.dot.nop@gmail.com> | 2013-07-31 21:51:14 +0200 |
commit | a060a1ad9655dede51f842873672652bf78a3e8e (patch) | |
tree | 0d7a4acf67c5b1f319e7b0036fef893a64b753a8 | |
parent | e418b2e7bb814309641b5b8152a5401f1dc4904a (diff) | |
download | busybox-w32-a060a1ad9655dede51f842873672652bf78a3e8e.tar.gz busybox-w32-a060a1ad9655dede51f842873672652bf78a3e8e.tar.bz2 busybox-w32-a060a1ad9655dede51f842873672652bf78a3e8e.zip |
awk: Fix handling of functions with empty body
ammend b79a0fef99627c457548e804fcd6e162b116cbe8 to properly
handle functions defined in another scope.
Signed-off-by: Bernhard Reutner-Fischer <rep.dot.nop@gmail.com>
-rw-r--r-- | editors/awk.c | 2 | ||||
-rwxr-xr-x | testsuite/awk.tests | 28 |
2 files changed, 29 insertions, 1 deletions
diff --git a/editors/awk.c b/editors/awk.c index a2e20215b..77784dfc1 100644 --- a/editors/awk.c +++ b/editors/awk.c | |||
@@ -2662,7 +2662,7 @@ static var *evaluate(node *op, var *res) | |||
2662 | const char *sv_progname; | 2662 | const char *sv_progname; |
2663 | 2663 | ||
2664 | /* The body might be empty, still has to eval the args */ | 2664 | /* The body might be empty, still has to eval the args */ |
2665 | if (!op->r.n->info) | 2665 | if (!op->r.n->info && !op->r.f->body.first) |
2666 | syntax_error(EMSG_UNDEF_FUNC); | 2666 | syntax_error(EMSG_UNDEF_FUNC); |
2667 | 2667 | ||
2668 | vbeg = v = nvalloc(op->r.f->nargs + 1); | 2668 | vbeg = v = nvalloc(op->r.f->nargs + 1); |
diff --git a/testsuite/awk.tests b/testsuite/awk.tests index 160f460a5..6af6072b8 100755 --- a/testsuite/awk.tests +++ b/testsuite/awk.tests | |||
@@ -44,6 +44,34 @@ testing "awk handles empty function f(arg){}" \ | |||
44 | "L1\n\nL2\n\n" \ | 44 | "L1\n\nL2\n\n" \ |
45 | "" "" | 45 | "" "" |
46 | 46 | ||
47 | prg=' | ||
48 | function outer_fun() { | ||
49 | return 1 | ||
50 | } | ||
51 | END { | ||
52 | i=1 | ||
53 | print "L" i "\n" | ||
54 | i += outer_fun() | ||
55 | print "L" i "\n" | ||
56 | }' | ||
57 | testing "awk properly handles function from other scope" \ | ||
58 | "awk '$prg'" \ | ||
59 | "L1\n\nL2\n\n" \ | ||
60 | "" "" | ||
61 | |||
62 | prg=' | ||
63 | END { | ||
64 | i=1 | ||
65 | print "L" i "\n" | ||
66 | i + trigger_error_fun() | ||
67 | print "L" i "\n" | ||
68 | }' | ||
69 | testing "awk properly handles undefined function" \ | ||
70 | "awk '$prg' 2>&1" \ | ||
71 | "L1\n\nawk: cmd. line:5: Call to undefined function\n" \ | ||
72 | "" "" | ||
73 | |||
74 | |||
47 | optional DESKTOP | 75 | optional DESKTOP |
48 | testing "awk hex const 1" "awk '{ print or(0xffffffff,1) }'" "4294967295\n" "" "\n" | 76 | testing "awk hex const 1" "awk '{ print or(0xffffffff,1) }'" "4294967295\n" "" "\n" |
49 | testing "awk hex const 2" "awk '{ print or(0x80000000,1) }'" "2147483649\n" "" "\n" | 77 | testing "awk hex const 2" "awk '{ print or(0x80000000,1) }'" "2147483649\n" "" "\n" |