aboutsummaryrefslogtreecommitdiff
path: root/editors/awk.c
diff options
context:
space:
mode:
authorDenys Vlasenko <vda.linux@googlemail.com>2021-06-30 12:52:51 +0200
committerDenys Vlasenko <vda.linux@googlemail.com>2021-06-30 12:52:51 +0200
commitd7354df169603807fe2ac4f8a0f9f72c9703184f (patch)
treef93f4b2564b617420d4c4b3b7032b0e557e999ea /editors/awk.c
parentca9278ee5855a91a5521960d3743809f47ed27b8 (diff)
downloadbusybox-w32-d7354df169603807fe2ac4f8a0f9f72c9703184f.tar.gz
busybox-w32-d7354df169603807fe2ac4f8a0f9f72c9703184f.tar.bz2
busybox-w32-d7354df169603807fe2ac4f8a0f9f72c9703184f.zip
awk: evaluate all, even superfluous function args
function old new delta evaluate 3128 3135 +7 Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Diffstat (limited to 'editors/awk.c')
-rw-r--r--editors/awk.c19
1 files changed, 12 insertions, 7 deletions
diff --git a/editors/awk.c b/editors/awk.c
index 0fbca0433..47bbc10a6 100644
--- a/editors/awk.c
+++ b/editors/awk.c
@@ -2910,7 +2910,7 @@ static var *evaluate(node *op, var *res)
2910 case XC( OC_FUNC ): { 2910 case XC( OC_FUNC ): {
2911 var *tv, *sv_fnargs; 2911 var *tv, *sv_fnargs;
2912 const char *sv_progname; 2912 const char *sv_progname;
2913 int nargs1, i; 2913 int nargs, i;
2914 2914
2915 debug_printf_eval("FUNC\n"); 2915 debug_printf_eval("FUNC\n");
2916 2916
@@ -2918,17 +2918,22 @@ static var *evaluate(node *op, var *res)
2918 syntax_error(EMSG_UNDEF_FUNC); 2918 syntax_error(EMSG_UNDEF_FUNC);
2919 2919
2920 /* The body might be empty, still has to eval the args */ 2920 /* The body might be empty, still has to eval the args */
2921 nargs1 = op->r.f->nargs + 1; 2921 nargs = op->r.f->nargs;
2922 tv = nvalloc(nargs1); 2922 tv = nvalloc(nargs);
2923 i = 0; 2923 i = 0;
2924 while (op1) { 2924 while (op1) {
2925//TODO: explain why one iteration is done even for the case p->r.f->nargs == 0
2926 var *arg = evaluate(nextarg(&op1), v1); 2925 var *arg = evaluate(nextarg(&op1), v1);
2926 if (i == nargs) {
2927 /* call with more arguments than function takes.
2928 * (gawk warns: "warning: function 'f' called with more arguments than declared").
2929 * They are still evaluated, but discarded: */
2930 clrvar(arg);
2931 continue;
2932 }
2927 copyvar(&tv[i], arg); 2933 copyvar(&tv[i], arg);
2928 tv[i].type |= VF_CHILD; 2934 tv[i].type |= VF_CHILD;
2929 tv[i].x.parent = arg; 2935 tv[i].x.parent = arg;
2930 if (++i >= op->r.f->nargs) 2936 i++;
2931 break;
2932 } 2937 }
2933 2938
2934 sv_fnargs = fnargs; 2939 sv_fnargs = fnargs;
@@ -2936,7 +2941,7 @@ static var *evaluate(node *op, var *res)
2936 2941
2937 fnargs = tv; 2942 fnargs = tv;
2938 res = evaluate(op->r.f->body.first, res); 2943 res = evaluate(op->r.f->body.first, res);
2939 nvfree(fnargs, nargs1); 2944 nvfree(fnargs, nargs);
2940 2945
2941 g_progname = sv_progname; 2946 g_progname = sv_progname;
2942 fnargs = sv_fnargs; 2947 fnargs = sv_fnargs;