Skip to content

Commit

Permalink
ext2fs: fix -Walloc-size
Browse files Browse the repository at this point in the history
GCC 14 introduces a new -Walloc-size included in -Wextra which gives:
```
lib/ext2fs/hashmap.c:37:36: warning: allocation of insufficient size ‘1’ for type ‘struct ext2fs_hashmap’ with size ‘20’ [-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(...)`. GCC then sees we're not
doing anything wrong.

Signed-off-by: Sam James <[email protected]>
Link: https://lore.kernel.org/r/[email protected]
Signed-off-by: Theodore Ts'o <[email protected]>
  • Loading branch information
thesamesam authored and tytso committed Apr 17, 2024
1 parent 1275bba commit aa11dab
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions lib/ext2fs/hashmap.c
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ struct ext2fs_hashmap *ext2fs_hashmap_create(
uint32_t(*hash_fct)(const void*, size_t),
void(*free_fct)(void*), size_t size)
{
struct ext2fs_hashmap *h = calloc(sizeof(struct ext2fs_hashmap) +
sizeof(struct ext2fs_hashmap_entry) * size, 1);
struct ext2fs_hashmap *h = calloc(1, sizeof(struct ext2fs_hashmap) +
sizeof(struct ext2fs_hashmap_entry) * size);
if (!h)
return NULL;

Expand Down

0 comments on commit aa11dab

Please sign in to comment.