~registry/kmod/master

« back to all changes in this revision

Viewing changes to tools/depmod.c

  • Committer: Lucas De Marchi
  • Author(s): Sam James
  • Date: 2023-11-06 00:22:05 UTC
  • Revision ID: git-v1:3af2f475b0b729f20279f2ce488cc9f727f0b763
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>

Show diffs side-by-side

added added

removed removed

Lines of Context:
190
190
{
191
191
        struct index_node *node;
192
192
 
193
 
        node = NOFAIL(calloc(sizeof(struct index_node), 1));
 
193
        node = NOFAIL(calloc(1, sizeof(struct index_node)));
194
194
        node->prefix = NOFAIL(strdup(""));
195
195
        node->first = INDEX_CHILDMAX;
196
196
 
253
253
                values = &(*values)->next;
254
254
 
255
255
        len = strlen(value);
256
 
        v = NOFAIL(calloc(sizeof(struct index_value) + len + 1, 1));
 
256
        v = NOFAIL(calloc(1, sizeof(struct index_value) + len + 1));
257
257
        v->next = *values;
258
258
        v->priority = priority;
259
259
        memcpy(v->value, value, len + 1);
284
284
                                struct index_node *n;
285
285
 
286
286
                                /* New child is copy of node with prefix[j+1..N] */
287
 
                                n = NOFAIL(calloc(sizeof(struct index_node), 1));
 
287
                                n = NOFAIL(calloc(1, sizeof(struct index_node)));
288
288
                                memcpy(n, node, sizeof(struct index_node));
289
289
                                n->prefix = NOFAIL(strdup(&prefix[j+1]));
290
290
 
313
313
                                node->first = ch;
314
314
                        if (ch > node->last)
315
315
                                node->last = ch;
316
 
                        node->children[ch] = NOFAIL(calloc(sizeof(struct index_node), 1));
 
316
                        node->children[ch] = NOFAIL(calloc(1, sizeof(struct index_node)));
317
317
 
318
318
                        child = node->children[ch];
319
319
                        child->prefix = NOFAIL(strdup(&key[i+1]));