Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 910D5C4332F for ; Tue, 7 Nov 2023 23:41:30 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235629AbjKGXlb (ORCPT ); Tue, 7 Nov 2023 18:41:31 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53512 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235478AbjKGXlX (ORCPT ); Tue, 7 Nov 2023 18:41:23 -0500 Received: from smtp.gentoo.org (dev.gentoo.org [IPv6:2001:470:ea4a:1:5054:ff:fec7:86e4]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5BC30526F for ; Tue, 7 Nov 2023 15:31:35 -0800 (PST) From: Sam James To: linux-ext4@vger.kernel.org Cc: Sam James Subject: [PATCH e2fsprogs] ext2fs: Fix -Walloc-size Date: Tue, 7 Nov 2023 23:31:20 +0000 Message-ID: <20231107233122.2013191-1-sam@gentoo.org> X-Mailer: git-send-email 2.42.1 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-ext4@vger.kernel.org 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 --- lib/ext2fs/hashmap.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/ext2fs/hashmap.c b/lib/ext2fs/hashmap.c index 697b2bcc..15794673 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; -- 2.42.1