aboutsummaryrefslogtreecommitdiffstats
path: root/builtin.c
diff options
context:
space:
mode:
Diffstat (limited to 'builtin.c')
-rw-r--r--builtin.c8
1 files changed, 8 insertions, 0 deletions
diff --git a/builtin.c b/builtin.c
index 91cd142f..125468ba 100644
--- a/builtin.c
+++ b/builtin.c
@@ -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);