From: Sam James Date: Sun, 5 Nov 2023 22:02:25 +0000 (+0000) Subject: tools: depmod: fix -Walloc-size X-Git-Tag: v32~12 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=3af2f475b0b729f20279f2ce488cc9f727f0b763;p=thirdparty%2Fkmod.git tools: depmod: fix -Walloc-size GCC 14 introduces a new -Walloc-size included in -Wextra which gives: ``` tools/depmod.c:192:14: warning: allocation of insufficient size ‘1’ for type ‘struct index_node’ with size ‘1048’ [-Walloc-size] tools/depmod.c:255:11: warning: allocation of insufficient size ‘1’ for type ‘struct index_value’ with size ‘16’ [-Walloc-size] tools/depmod.c:286:35: warning: allocation of insufficient size ‘1’ for type ‘struct index_node’ with size ‘1048’ [-Walloc-size] tools/depmod.c:315:44: warning: allocation of insufficient size ‘1’ for type ‘struct index_node’ with size ‘1048’ [-Walloc-size] ``` The calloc prototype is: ``` void *calloc(size_t nmemb, size_t size); ``` So, just swap the number of members and size arguments to match the prototype, as we're initialising 1 struct of size `sizeof(struct ...)`. GCC then sees we're not doing anything wrong. Signed-off-by: Sam James --- diff --git a/tools/depmod.c b/tools/depmod.c index 630fef9c..ab8513b2 100644 --- a/tools/depmod.c +++ b/tools/depmod.c @@ -190,7 +190,7 @@ static struct index_node *index_create(void) { struct index_node *node; - node = NOFAIL(calloc(sizeof(struct index_node), 1)); + node = NOFAIL(calloc(1, sizeof(struct index_node))); node->prefix = NOFAIL(strdup("")); node->first = INDEX_CHILDMAX; @@ -253,7 +253,7 @@ static int index_add_value(struct index_value **values, values = &(*values)->next; len = strlen(value); - v = NOFAIL(calloc(sizeof(struct index_value) + len + 1, 1)); + v = NOFAIL(calloc(1, sizeof(struct index_value) + len + 1)); v->next = *values; v->priority = priority; memcpy(v->value, value, len + 1); @@ -284,7 +284,7 @@ static int index_insert(struct index_node *node, const char *key, struct index_node *n; /* New child is copy of node with prefix[j+1..N] */ - n = NOFAIL(calloc(sizeof(struct index_node), 1)); + n = NOFAIL(calloc(1, sizeof(struct index_node))); memcpy(n, node, sizeof(struct index_node)); n->prefix = NOFAIL(strdup(&prefix[j+1])); @@ -313,7 +313,7 @@ static int index_insert(struct index_node *node, const char *key, node->first = ch; if (ch > node->last) node->last = ch; - node->children[ch] = NOFAIL(calloc(sizeof(struct index_node), 1)); + node->children[ch] = NOFAIL(calloc(1, sizeof(struct index_node))); child = node->children[ch]; child->prefix = NOFAIL(strdup(&key[i+1]));