diff options
author | Yorhel <git@yorhel.nl> | 2023-01-22 12:40:33 +0100 |
---|---|---|
committer | Yorhel <git@yorhel.nl> | 2023-01-22 12:40:35 +0100 |
commit | 3213c85ec0bdaadaffa0052fe315618bf03d3e20 (patch) | |
tree | c85c515a93bdd7adaf95aa7636182b365e556f92 | |
parent | e9b4161b13faeb0ccfaa64727c3da2e37354ccd3 (diff) |
Get rid of all VLAs
Fixes #102 again, but for ADC. Might also fix other VLA-related bugs.
-rw-r--r-- | src/db.c | 4 | ||||
-rw-r--r-- | src/fl_util.c | 32 | ||||
-rw-r--r-- | src/hub.c | 2 | ||||
-rw-r--r-- | src/vars.c | 8 |
4 files changed, 22 insertions, 24 deletions
@@ -1418,8 +1418,8 @@ static void cert_init() { gnutls_certificate_set_x509_key(db_certificate, &cert, 1, key); // Generate keyprint - size_t len = 8*1024; // should be enough - unsigned char crtder[len]; + unsigned char crtder[8*1024]; // should be enough + size_t len = sizeof crtder; char raw[32]; g_assert(gnutls_x509_crt_export(cert, GNUTLS_X509_FMT_DER, (void *)crtder, &len) == 0); gnutls_datum_t dat; diff --git a/src/fl_util.c b/src/fl_util.c index 645c4b9..d69b196 100644 --- a/src/fl_util.c +++ b/src/fl_util.c @@ -423,7 +423,7 @@ int fl_search_rec(fl_list_t *parent, fl_search_t *s, fl_list_t **res, int max) { // weed out stuff from 'and' if it's already matched in parent (I'm assuming // that stuff matching the parent of parent has already been removed) GRegex **o = s->and; - GRegex *nand[fl_search_and_len(o)+1]; + GRegex **nand = g_malloc(sizeof(GRegex *) * (fl_search_and_len(o)+1)); int i = 0; for(; o&&*o; o++) if(G_LIKELY(!parent->parent || !g_regex_match(*o, parent->name, 0, NULL))) @@ -441,6 +441,7 @@ int fl_search_rec(fl_list_t *parent, fl_search_t *s, fl_list_t **res, int max) { n += fl_search_rec(f, s, res+n, max-n); } s->and = o; + g_free(nand); return n; } @@ -450,24 +451,21 @@ gboolean fl_search_match_full(fl_list_t *fl, fl_search_t *s) { // weed out stuff from 'and' if it's already matched in any of its parents. GRegex **oand = s->and; int len = fl_search_and_len(s->and); - GRegex *nand[len]; - fl_list_t *p = fl->parent; - int i; - memcpy(nand, s->and, len*sizeof(GRegex *)); - for(; p && p->parent; p=p->parent) - for(i=0; i<len; i++) - if(G_UNLIKELY(nand[i] && g_regex_match(nand[i], p->name, 0, NULL))) - nand[i] = NULL; - GRegex *and[len]; - int j=0; - for(i=0; i<len; i++) - if(nand[i]) - and[j++] = nand[i]; - and[j] = NULL; - s->and = and; - // and now match + GRegex **nand = g_malloc(sizeof(GRegex *) * (len+1)); + fl_list_t *p; + int i, j=0; + for(i=0; i<len; i++) { + for(p=fl->parent; p && p->parent; p=p->parent) + if(G_UNLIKELY(oand[i] && g_regex_match(oand[i], p->name, 0, NULL))) + break; + if(!(p && p->parent)) + nand[j++] = oand[i]; + } + nand[j] = NULL; + s->and = nand; gboolean r = fl_search_match(fl, s); s->and = oand; + g_free(nand); return r; } @@ -1028,7 +1028,7 @@ static void adc_sch(hub_t *hub, adc_cmd_t *cmd) { int i = 0; int max = (u->hasudp4 && u->udp4) || (u->hasudp6 && u->udp6) ? 10 : 5; - fl_list_t *res[max]; + fl_list_t *res[10]; // TTH lookup if(tr) { @@ -457,14 +457,12 @@ static gboolean s_dl_inc_dir(guint64 hub, const char *key, const char *val, GErr return FALSE; } - char *tmp = val ? g_strdup(val) : i_dl_inc_dir(dl); - char nval[strlen(tmp)+1]; - strcpy(nval, tmp); - g_free(tmp); + char *nval = val ? g_strdup(val) : i_dl_inc_dir(dl); // make sure it exists if(g_mkdir_with_parents(nval, 0777)) { g_set_error(err, 1, 0, "Error creating the directory: %s", g_strerror(errno)); + g_free(nval); return FALSE; } @@ -474,6 +472,7 @@ static gboolean s_dl_inc_dir(guint64 hub, const char *key, const char *val, GErr if(stat(bd, &b) == 0) { if(stat(nval, &a) < 0) { g_set_error(err, 1, 0, "Error stat'ing %s: %s", nval, g_strerror(errno)); + g_free(nval); return FALSE; } if(a.st_dev != b.st_dev) @@ -482,6 +481,7 @@ static gboolean s_dl_inc_dir(guint64 hub, const char *key, const char *val, GErr } db_vars_set(hub, key, val); + g_free(nval); return TRUE; } |