diff options
author | Sam James <sam@gentoo.org> | 2023-11-05 22:02:25 +0000 |
---|---|---|
committer | Lucas De Marchi <lucas.de.marchi@gmail.com> | 2023-11-05 18:22:05 -0600 |
commit | 3af2f475b0b729f20279f2ce488cc9f727f0b763 (patch) | |
tree | 60bfb801fb6449684096b7b267b5b1edf3920a2c | |
parent | ecef7c131618bbd9c559924ecae55764089db0dd (diff) | |
download | kmod-3af2f475b0b729f20279f2ce488cc9f727f0b763.tar.gz |
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 <sam@gentoo.org>
-rw-r--r-- | tools/depmod.c | 8 |
1 files changed, 4 insertions, 4 deletions
diff --git a/tools/depmod.c b/tools/depmod.c index 630fef9..ab8513b 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])); |