aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBernhard Reutner-Fischer <rep.dot.nop@gmail.com>2013-07-31 15:29:20 +0200
committerBernhard Reutner-Fischer <rep.dot.nop@gmail.com>2013-07-31 21:51:14 +0200
commita060a1ad9655dede51f842873672652bf78a3e8e (patch)
tree0d7a4acf67c5b1f319e7b0036fef893a64b753a8
parente418b2e7bb814309641b5b8152a5401f1dc4904a (diff)
downloadbusybox-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.c2
-rwxr-xr-xtestsuite/awk.tests28
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
47prg='
48function outer_fun() {
49 return 1
50}
51END {
52 i=1
53 print "L" i "\n"
54 i += outer_fun()
55 print "L" i "\n"
56}'
57testing "awk properly handles function from other scope" \
58 "awk '$prg'" \
59 "L1\n\nL2\n\n" \
60 "" ""
61
62prg='
63END {
64 i=1
65 print "L" i "\n"
66 i + trigger_error_fun()
67 print "L" i "\n"
68}'
69testing "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
47optional DESKTOP 75optional DESKTOP
48testing "awk hex const 1" "awk '{ print or(0xffffffff,1) }'" "4294967295\n" "" "\n" 76testing "awk hex const 1" "awk '{ print or(0xffffffff,1) }'" "4294967295\n" "" "\n"
49testing "awk hex const 2" "awk '{ print or(0x80000000,1) }'" "2147483649\n" "" "\n" 77testing "awk hex const 2" "awk '{ print or(0x80000000,1) }'" "2147483649\n" "" "\n"