diff options
author | Arnold D. Robbins <arnold@skeeve.com> | 2015-01-30 10:06:16 +0200 |
---|---|---|
committer | Arnold D. Robbins <arnold@skeeve.com> | 2015-01-30 10:06:16 +0200 |
commit | 1bd1b885c7dd16b5e4ab78c040312f6f7d742784 (patch) | |
tree | d7e1c0c8dfdf4002d9a0c7f4bf634cafe2663a42 /symbol.c | |
parent | 5153d0f04b7ad460b23ae5a011061f7b93a122ef (diff) | |
download | egawk-1bd1b885c7dd16b5e4ab78c040312f6f7d742784.tar.gz egawk-1bd1b885c7dd16b5e4ab78c040312f6f7d742784.tar.bz2 egawk-1bd1b885c7dd16b5e4ab78c040312f6f7d742784.zip |
Disallow calling a function parameter. Check params are not function names.
Diffstat (limited to 'symbol.c')
-rw-r--r-- | symbol.c | 55 |
1 files changed, 55 insertions, 0 deletions
@@ -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; |