aboutsummaryrefslogtreecommitdiffstats
path: root/symbol.c
diff options
context:
space:
mode:
Diffstat (limited to 'symbol.c')
-rw-r--r--symbol.c13
1 files changed, 11 insertions, 2 deletions
diff --git a/symbol.c b/symbol.c
index 4ff9c78a..c775c931 100644
--- a/symbol.c
+++ b/symbol.c
@@ -376,13 +376,20 @@ get_symbols(SYMBOL_TYPE what, int sort)
long max;
NODE *the_table;
+ /*
+ * 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.
+ */
+
if (what == FUNCTION) {
count = func_count;
the_table = func_table;
max = the_table->table_size * 2;
list = assoc_list(the_table, "@unsorted", ASORTI);
- emalloc(table, NODE **, (count + 1) * sizeof(NODE *), "symbol_list");
+ emalloc(table, NODE **, (count + 1) * sizeof(NODE *), "get_symbols");
for (i = j = 0; i < max; i += 2) {
r = list[i+1];
@@ -391,6 +398,7 @@ get_symbols(SYMBOL_TYPE what, int sort)
assert(r->type == Node_func);
table[j++] = r;
}
+ count = j;
} else { /* what == VARIABLE */
the_table = symbol_table;
count = var_count;
@@ -399,7 +407,7 @@ get_symbols(SYMBOL_TYPE what, int sort)
max = the_table->table_size * 2;
list = assoc_list(the_table, "@unsorted", ASORTI);
- emalloc(table, NODE **, (count + 1) * sizeof(NODE *), "symbol_list");
+ emalloc(table, NODE **, (count + 1) * sizeof(NODE *), "get_symbols");
for (i = j = 0; i < max; i += 2) {
r = list[i+1];
@@ -407,6 +415,7 @@ get_symbols(SYMBOL_TYPE what, int sort)
continue;
table[j++] = r;
}
+ count = j;
}
efree(list);