diff options
-rw-r--r-- | ChangeLog | 12 | ||||
-rw-r--r-- | array.c | 9 | ||||
-rw-r--r-- | awk.h | 1 | ||||
-rw-r--r-- | builtin.c | 14 | ||||
-rw-r--r-- | field.c | 8 |
5 files changed, 38 insertions, 6 deletions
@@ -1,3 +1,15 @@ +2020-06-14 Arnold D. Robbins <arnold@skeeve.com> + + Disallow SYMTAB and FUNCTAB as destination arguments to builtin + functions that clear arrays: + + * awk.h (check_symtab_functab): Add declaration. + * array.c (asort_actual): Call it in check for second argument. + * builtin.c (check_symtab_functab): New function. + (do_match): Call it in check for third argument. + * field.c (do_patsplit, do_split): Call it in checks for fourth and + second arguments. + 2020-06-12 Arnold D. Robbins <arnold@skeeve.com> * array.c (asort_actual): If SYMTAB or FUNCTAB is the second argument, @@ -824,12 +824,9 @@ asort_actual(int nargs, sort_context_t ctxt) fatal(_("%s: second argument is not an array"), ctxt == ASORT ? "asort" : "asorti"); } - if (dest == symbol_table) - fatal(_("%s: SYMTAB cannot be used as second argument"), - ctxt == ASORT ? "asort" : "asorti"); - else if (dest == func_table) - fatal(_("%s: FUNCTAB cannot be used as second argument"), - ctxt == ASORT ? "asort" : "asorti"); + check_symtab_functab(dest, + ctxt == ASORT ? "asort" : "asorti", + _("%s: cannot use %s as second argument")); } array = POP_PARAM(); @@ -1498,6 +1498,7 @@ extern NODE *do_typeof(int nargs); extern int strncasecmpmbs(const unsigned char *, const unsigned char *, size_t); extern int sanitize_exit_status(int status); +extern void check_symtab_functab(NODE *dest, const char *fname, const char *msg); /* debug.c */ extern void init_debug(void); extern int debug_prog(INSTRUCTION *pc); @@ -2678,6 +2678,8 @@ do_match(int nargs) dest = POP_PARAM(); if (dest->type != Node_var_array) fatal(_("match: third argument is not an array")); + check_symtab_functab(dest, "match", + _("%s: cannot use %s as third argument")); assoc_clear(dest); } tre = POP(); @@ -4328,3 +4330,15 @@ fmt: } return buf; } + + +/* check_symtab_functab --- check if dest is SYMTAB or FUNCTAB, fatal if so */ + +void +check_symtab_functab(NODE *dest, const char *fname, const char *msg) +{ + if (dest == symbol_table) + fatal(msg, fname, "SYMTAB"); + else if (dest == func_table) + fatal(msg, fname, "FUNCTAB"); +} @@ -980,6 +980,8 @@ do_split(int nargs) sep_arr = POP_PARAM(); if (sep_arr->type != Node_var_array) fatal(_("split: fourth argument is not an array")); + check_symtab_functab(sep_arr, "split", + _("%s: cannot use %s as fourth argument")); if ((do_lint_extensions || do_lint_old) && ! warned) { warned = true; lintwarn(_("split: fourth argument is a gawk extension")); @@ -990,6 +992,8 @@ do_split(int nargs) arr = POP_PARAM(); if (arr->type != Node_var_array) fatal(_("split: second argument is not an array")); + check_symtab_functab(arr, "split", + _("%s: cannot use %s as second argument")); if (sep_arr != NULL) { if (sep_arr == arr) @@ -1073,11 +1077,15 @@ do_patsplit(int nargs) sep_arr = POP_PARAM(); if (sep_arr->type != Node_var_array) fatal(_("patsplit: fourth argument is not an array")); + check_symtab_functab(sep_arr, "patsplit", + _("%s: cannot use %s as fourth argument")); } sep = POP(); arr = POP_PARAM(); if (arr->type != Node_var_array) fatal(_("patsplit: second argument is not an array")); + check_symtab_functab(arr, "patsplit", + _("%s: cannot use %s as second argument")); src = TOP_STRING(); |