aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSergey Poznyakoff <gray@gnu.org>2021-05-07 17:28:17 +0300
committerSergey Poznyakoff <gray@gnu.org>2021-05-07 17:28:17 +0300
commit9113cc2d91f24b3a8bca5d6444d61212c3b4db29 (patch)
tree38fc669f91b3cc79e11695e4cd55a28588f22d91
parentc03388de6e2e63dd75abe91e63b237e1f29ecf99 (diff)
downloadcflow-9113cc2d91f24b3a8bca5d6444d61212c3b4db29.tar.gz
cflow-9113cc2d91f24b3a8bca5d6444d61212c3b4db29.tar.bz2
Fix incorrect assumptions about number of symbols in the symbol table.
* src/symbol.c (collect_data): New member: count. (collect_processor,collect_list_entry): Reallocate the syn array as needed. (collect_symbols): Initialize sym to NULL and count to 0.
-rw-r--r--src/symbol.c21
1 files changed, 11 insertions, 10 deletions
diff --git a/src/symbol.c b/src/symbol.c
index f497b14..290f3c5 100644
--- a/src/symbol.c
+++ b/src/symbol.c
@@ -298,6 +298,7 @@ struct collect_data {
Symbol **sym;
int (*sel)(Symbol *p);
size_t index;
+ size_t count;
};
static bool
@@ -308,9 +309,10 @@ collect_processor(void *data, void *proc_data)
Symbol *s;
for (s = t->sym; s; s = s->next) {
if (cd->sel(s)) {
- if (cd->sym)
- cd->sym[cd->index] = s;
- cd->index++;
+ if (cd->index == cd->count) {
+ cd->sym = x2nrealloc(cd->sym, &cd->count, sizeof(cd->sym[0]));
+ }
+ cd->sym[cd->index++] = s;
}
}
return true;
@@ -322,8 +324,10 @@ collect_list_entry(void *item, void *proc_data)
Symbol *s = item;
struct collect_data *cd = proc_data;
if (cd->sel(s)) {
- cd->sym[cd->index] = s;
- cd->index++;
+ if (cd->index == cd->count) {
+ cd->sym = x2nrealloc(cd->sym, &cd->count, sizeof(cd->sym[0]));
+ }
+ cd->sym[cd->index++] = s;
}
return 0;
}
@@ -333,12 +337,9 @@ collect_symbols(Symbol ***return_sym, int (*sel)(Symbol *p),
size_t reserved_slots)
{
struct collect_data cdata;
- size_t size;
- size = hash_get_n_entries(symbol_table)
- + linked_list_size(static_func_list)
- + linked_list_size(unit_local_list);
- cdata.sym = xcalloc(size + reserved_slots, sizeof(*cdata.sym));
+ cdata.sym = NULL;
+ cdata.count = 0;
cdata.index = 0;
cdata.sel = sel;
hash_do_for_each(symbol_table, collect_processor, &cdata);

Return to:

Send suggestions and report system problems to the System administrator.