From 1bd1b885c7dd16b5e4ab78c040312f6f7d742784 Mon Sep 17 00:00:00 2001 From: "Arnold D. Robbins" Date: Fri, 30 Jan 2015 10:06:16 +0200 Subject: Disallow calling a function parameter. Check params are not function names. --- symbol.c | 55 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) (limited to 'symbol.c') diff --git a/symbol.c b/symbol.c index 23e04c03..552c111e 100644 --- a/symbol.c +++ b/symbol.c @@ -625,6 +625,61 @@ load_symbols() unref(array); } +/* check_param_names --- make sure no parameter is the name of a function */ + +bool +check_param_names(void) +{ + int i, j, k; + NODE **list; + NODE *f; + long max; + bool result = true; + + max = func_table->table_size * 2; + + /* + * assoc_list() returns an array with two elements per awk array + * element. Elements i and i+1 in the C array represent the key + * and value of element j in the awk array. Thus the loops use += 2 + * to go through the awk array. + * + * In this case, the name is in list[i], and the function is + * in list[i+1]. Just what we need. + */ + + list = assoc_list(func_table, "@unsorted", ASORTI); + + /* + * You want linear searches? + * Have we got linear searches! + */ + for (i = 0; i < max; i += 2) { + f = list[i+1]; + if (f->type == Node_builtin_func || f->param_cnt == 0) + continue; + + /* loop over each param in function i */ + for (j = 0; j < f->param_cnt; j++) { + /* compare to function names */ + for (k = 0; k < max; k += 2) { + if (k == i) + continue; + if (strcmp(f->fparms[j].param, list[k]->stptr) == 0) { + error( + _("function `%s': can't use function `%s' as a parameter name"), + list[i]->stptr, + list[k]->stptr); + result = false; + } + } + } + } + + efree(list); + return result; +} + #define pool_size d.dl #define freei x.xi static INSTRUCTION *pool_list; -- cgit v1.2.3