diff options
author | Maria Matejka <mq@ucw.cz> | 2019-08-16 12:47:13 +0200 |
---|---|---|
committer | Maria Matejka <mq@ucw.cz> | 2020-05-01 15:19:12 +0200 |
commit | dccee408262262ab9a63403141b74a0d937284bc (patch) | |
tree | ad7bb7a080764687cf575ae66449da76341d98e0 /proto/ospf/ospf.c | |
parent | baac7009063d94799821422ecc63ea2af41561ea (diff) |
OSPF: variable-length array of size 0 replaced by alloca()'d pointer
NULL pointer is safer than a random pointer onto stack if this function
gets changed and eventually broken.
Diffstat (limited to 'proto/ospf/ospf.c')
-rw-r--r-- | proto/ospf/ospf.c | 6 |
1 files changed, 4 insertions, 2 deletions
diff --git a/proto/ospf/ospf.c b/proto/ospf/ospf.c index 29610f4a..3cb40283 100644 --- a/proto/ospf/ospf.c +++ b/proto/ospf/ospf.c @@ -1244,7 +1244,7 @@ ospf_sh_state(struct proto *P, int verbose, int reachable) uint num = p->gr->hash_entries; struct top_hash_entry *hea[num]; - struct top_hash_entry *hex[verbose ? num : 0]; + struct top_hash_entry **hex = verbose ? alloca(num * sizeof(struct top_hash_entry *)) : NULL; struct top_hash_entry *he; struct top_hash_entry *cnode = NULL; @@ -1289,7 +1289,9 @@ ospf_sh_state(struct proto *P, int verbose, int reachable) lsa_compare_ospf3 = !ospf2; qsort(hea, j1, sizeof(struct top_hash_entry *), lsa_compare_for_state); - qsort(hex, jx, sizeof(struct top_hash_entry *), ext_compare_for_state); + + if (verbose) + qsort(hex, jx, sizeof(struct top_hash_entry *), ext_compare_for_state); /* * This code is a bit tricky, we have a primary LSAs (router and |