aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--ChangeLog7
-rw-r--r--symbol.c13
2 files changed, 18 insertions, 2 deletions
diff --git a/ChangeLog b/ChangeLog
index e98a0f45..9305e7f2 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,10 @@
+2013-01-22 Arnold D. Robbins <arnold@skeeve.com>
+
+ * symbol.c (get_symbols): Reset count after each loop to only
+ sort the actual items retrieved. Thanks to Manuel Collado (by
+ way of Andrew Schorr) for reporting the bug. Also add some
+ commentary and fix function name in emalloc calls.
+
2013-01-20 Arnold D. Robbins <arnold@skeeve.com>
* re.c (regexflags2str): New routine.
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);