diff options
author | Arnold D. Robbins <arnold@skeeve.com> | 2022-02-04 13:28:10 +0200 |
---|---|---|
committer | Arnold D. Robbins <arnold@skeeve.com> | 2022-02-04 13:28:10 +0200 |
commit | 313a4000d906aa233ce8b597031f660d6281f690 (patch) | |
tree | 7e95aa624b75692a0267613fa378390e1658d8b7 | |
parent | d96d55d7d23ee27c49cf7055956007de5f3432db (diff) | |
download | egawk-313a4000d906aa233ce8b597031f660d6281f690.tar.gz egawk-313a4000d906aa233ce8b597031f660d6281f690.tar.bz2 egawk-313a4000d906aa233ce8b597031f660d6281f690.zip |
Start fixing indirect calls of builtins.
-rw-r--r-- | ChangeLog | 11 | ||||
-rw-r--r-- | builtin.c | 8 | ||||
-rw-r--r-- | interpret.h | 4 |
3 files changed, 23 insertions, 0 deletions
@@ -1,3 +1,14 @@ +2022-02-04 Arnold D. Robbins <arnold@skeeve.com> + + Start fixing issues with indirect calls of builtins. + Thanks to Denis Shirokov <cosmogen@gmail.com> for the initial report. + Much more remains to be done. + + * builtin.c (do_length): Check number of arguments, fatal if not one. + If passed Node_var_new, turn it into the null string. + * interpret.h (r_interpret): For Op_indirect_call, pop the function + name off the stack. + 2022-01-05 Arnold D. Robbins <arnold@skeeve.com> * awkgram.y (change_namespace): New function. Extracted from @@ -538,6 +538,10 @@ do_length(int nargs) NODE *tmp; size_t len; + // indirect call can pass too many arguments + if (nargs != 1) + fatal(_("length: called with %d arguments"), nargs); + tmp = POP(); if (tmp->type == Node_var_array) { static bool warned = false; @@ -561,6 +565,10 @@ do_length(int nargs) size = assoc_length(tmp); return make_number(size); + } else if (tmp->type == Node_var_new) { + // this can happen from an indirect call + DEREF(tmp); + tmp = dupnode(Nnull_string); } assert(tmp->type == Node_val); diff --git a/interpret.h b/interpret.h index d52d537e..071d6497 100644 --- a/interpret.h +++ b/interpret.h @@ -1132,6 +1132,7 @@ match_re: NODE *f = NULL; int arg_count; char save; + NODE *function_name; arg_count = (pc + 1)->expr_count; t1 = PEEK(arg_count); /* indirect var */ @@ -1174,6 +1175,9 @@ match_re: r = the_func(arg_count); str_restore(t1, save); + function_name = POP(); // pop function name off stack + DEREF(function_name); + PUSH(r); break; } else if (f->type != Node_func) { |