From 8d424a9c8a6fab5039414834c6e34151c577e7da Mon Sep 17 00:00:00 2001 From: P. J. McDermott Date: Sun, 08 Sep 2013 11:22:26 -0400 Subject: Add patch to fix handling of empty awk functions. --- (limited to 'patches') diff --git a/patches/02_awk-fix-handling-of-functions-with-empty-body.patch b/patches/02_awk-fix-handling-of-functions-with-empty-body.patch new file mode 100644 index 0000000..102e128 --- /dev/null +++ b/patches/02_awk-fix-handling-of-functions-with-empty-body.patch @@ -0,0 +1,88 @@ +From: Bernhard Reutner-Fischer +Date: Wed, 06 Mar 2013 20:01:05 +0000 +Date: Wed, 31 Jul 2013 13:29:20 +0000 +Origin: upstream, http://git.busybox.net/busybox/commit/?id=b79a0fef +Origin: upstream, http://git.busybox.net/busybox/commit/?id=a060a1ad +Subject: awk: Fix handling of functions with empty body + +This fixes the following error that occurs when building an unpatched GCC 4.7 +with BusyBox awk: + + awk: [...]/gcc/config/i386/i386-builtin-types.awk:164: Call to undefined function + +BusyBox awk throws this syntax error if the called function has no nodes in its +node chain (i.e. the function body is empty). + +--- +diff --git a/editors/awk.c b/editors/awk.c +index 3224788..77784df 100644 +--- a/editors/awk.c ++++ b/editors/awk.c +@@ -2661,7 +2661,8 @@ static var *evaluate(node *op, var *res) + var *vbeg, *v; + const char *sv_progname; + +- if (!op->r.f->body.first) ++ /* The body might be empty, still has to eval the args */ ++ if (!op->r.n->info && !op->r.f->body.first) + syntax_error(EMSG_UNDEF_FUNC); + + vbeg = v = nvalloc(op->r.f->nargs + 1); +diff --git a/testsuite/awk.tests b/testsuite/awk.tests +index f9c3b6b..6af6072 100755 +--- a/testsuite/awk.tests ++++ b/testsuite/awk.tests +@@ -25,6 +25,53 @@ testing "awk if string == " "awk 'BEGIN{if(\"a\"==\"ab\") print \"bar\"}'" "" + + # 4294967295 = 0xffffffff + testing "awk bitwise op" "awk '{ print or(4294967295,1) }'" "4.29497e+09\n" "" "\n" ++ ++# we were testing for a non-empty body when deciding if a function was ++# defined or not. The testcase below caused: ++# awk: cmd. line:8: Call to undefined function ++prg=' ++function empty_fun(count) { ++ # empty ++} ++END { ++ i=1 ++ print "L" i "\n" ++ empty_fun(i + i + ++i) ++ print "L" i "\n" ++}' ++testing "awk handles empty function f(arg){}" \ ++ "awk '$prg'" \ ++ "L1\n\nL2\n\n" \ ++ "" "" ++ ++prg=' ++function outer_fun() { ++ return 1 ++} ++END { ++ i=1 ++ print "L" i "\n" ++ i += outer_fun() ++ print "L" i "\n" ++}' ++testing "awk properly handles function from other scope" \ ++ "awk '$prg'" \ ++ "L1\n\nL2\n\n" \ ++ "" "" ++ ++prg=' ++END { ++ i=1 ++ print "L" i "\n" ++ i + trigger_error_fun() ++ print "L" i "\n" ++}' ++testing "awk properly handles undefined function" \ ++ "awk '$prg' 2>&1" \ ++ "L1\n\nawk: cmd. line:5: Call to undefined function\n" \ ++ "" "" ++ ++ + optional DESKTOP + testing "awk hex const 1" "awk '{ print or(0xffffffff,1) }'" "4.29497e+09\n" "" "\n" + testing "awk hex const 2" "awk '{ print or(0x80000000,1) }'" "2.14748e+09\n" "" "\n" -- cgit v0.9.1