From: Sam James Date: Tue, 7 Nov 2023 23:31:20 +0000 (+0000) Subject: ext2fs: fix -Walloc-size X-Git-Tag: v1.47.1-rc1~48 X-Git-Url: https://git.whamcloud.com/?a=commitdiff_plain;h=aa11daba2081da28ec70c557eefd5039a99555a3;p=tools%2Fe2fsprogs.git ext2fs: fix -Walloc-size 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 Link: https://lore.kernel.org/r/20231107233122.2013191-1-sam@gentoo.org Signed-off-by: Theodore Ts'o --- diff --git a/lib/ext2fs/hashmap.c b/lib/ext2fs/hashmap.c index 697b2bc..1579467 100644 --- a/lib/ext2fs/hashmap.c +++ b/lib/ext2fs/hashmap.c @@ -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;