Skip to contentSkip to conversation

ext2fs: Fix -Walloc-size

PATCH Applied Sam James 2 participants 2 messages Nov 7, 2023 – Apr 18, 2024

lore
Share & tools
lore

Sam James

author
#0 lore raw

PATCH 1/1 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.

---
 lib/ext2fs/hashmap.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
lib/ext2fs/hashmap.c +2 -2
index 697b2bcc..15794673 100644
@@ -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;
 
Signature · 1 line
2.42.1
#1 lore raw
Quoted 11 lines · Sam James

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);
```

[...]

Applied, thanks!

[1/1] ext2fs: Fix -Walloc-size

      commit: aa11daba2081da28ec70c557eefd5039a99555a3

Best regards,

Signature · 1 line
Theodore Ts'o <[email protected]>