From patchwork Sun Jan 21 23:41:12 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Mark Wielaard X-Patchwork-Id: 189859 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:2bc4:b0:101:a8e8:374 with SMTP id hx4csp2282362dyb; Sun, 21 Jan 2024 15:41:28 -0800 (PST) X-Google-Smtp-Source: AGHT+IFm/z/tLsU1Ua0RV9U+9hOSzY/+HKzeSPCsCWqS78FqhJ0i/XEogkXlIK/i9mpxrQ0xyeOH X-Received: by 2002:a05:622a:1648:b0:429:d727:3824 with SMTP id y8-20020a05622a164800b00429d7273824mr6495898qtj.134.1705880488117; Sun, 21 Jan 2024 15:41:28 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1705880488; cv=pass; d=google.com; s=arc-20160816; b=INd9NKw+AQmgmJpqAVUuAkdMI1Ozrb96m1j+GyFtNlGVprXlFTg9Oj/xYNGxtbloGg c+RouAN+1Uuf4GB/gwPj6R8RXLZ+YIcn5xLpIxfbXzAi08mHELxakkHW9wRwbDITiBH5 YnF+D3QzS29ta4USS7NlC+DbysLZ1YEVboDrNmM6DzXvd89NzdNm8zJ5YmVMmjVikMWV Ilx2EHTobjzVz3bfl9hu1nGx/8tiONxLehyIB6TdSWd4uBkPq+320qTlMpmO0gvf9l/l 5wRhnhuUHtoyDqtRxlxHULaMIprZJxr0qEIILSW9caj+BX5Hi8QbfA4Ou+uYzSg+2dPP inaw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:message-id:date:subject:cc:to:from:arc-filter :dmarc-filter:delivered-to; bh=CVdJyCt7xdtc5tsS08yl77BUFAnYqyS6a6vWhGfTCSY=; fh=dJd+3NRnVFvBaW/IXi0G9kHIpwH/063mGZ1m5fE8wt8=; b=mm0I1Oj4gyxmAUZtCX7ne2geFwm8yyimf9CHmoTxqxk79/pUAhQxZQe56QdzV/1CmR 299o5sipQX8WFC+wn9F/BNKgXQOIQjVsOi7vZhlbSo8XjLhiWuANUP/9jZyCZ3dSXWB7 RxdbLebgGtd9l0FnR+qLtNsPoSBrXgcBLtZ6GJr6c+1lHw89FJS5iFb2LD/xxmQlsZDY TjbwX75B6fcBIl02S3Y+FsYUkN+IpC4DoOIvBpPqHZecraunKGYt9gZrzwlAOHnQQ/rc o96z/RBt3QbgWuIW0gV0hL9u154XXFB0qlrEMRzNCW+RFRREZK3GJdSw0UHAtWT0gPFG 9cyQ== ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1); spf=pass (google.com: domain of binutils-bounces+ouuuleilei=gmail.com@sourceware.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="binutils-bounces+ouuuleilei=gmail.com@sourceware.org" Received: from server2.sourceware.org (server2.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id o15-20020a05622a044f00b004298dc51cb2si4420284qtx.772.2024.01.21.15.41.28 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 21 Jan 2024 15:41:28 -0800 (PST) Received-SPF: pass (google.com: domain of binutils-bounces+ouuuleilei=gmail.com@sourceware.org designates 8.43.85.97 as permitted sender) client-ip=8.43.85.97; Authentication-Results: mx.google.com; arc=pass (i=1); spf=pass (google.com: domain of binutils-bounces+ouuuleilei=gmail.com@sourceware.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="binutils-bounces+ouuuleilei=gmail.com@sourceware.org" Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id C41D53858415 for ; Sun, 21 Jan 2024 23:41:27 +0000 (GMT) X-Original-To: binutils@sourceware.org Delivered-To: binutils@sourceware.org Received: from gnu.wildebeest.org (gnu.wildebeest.org [45.83.234.184]) by sourceware.org (Postfix) with ESMTPS id 96D833858C56 for ; Sun, 21 Jan 2024 23:41:17 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 96D833858C56 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=klomp.org Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=klomp.org ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 96D833858C56 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=45.83.234.184 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1705880479; cv=none; b=VnlauHkkWxcv21mM4x9PhPQ97jNMX/Df9FflIa9Lh8BkpOfkXWzjH0iFWDgNWDT6Y9JKUTURLgTXjR2YRprtBn08amETQ6pDLkUyaLhp1VjuG8j0FPtN1A9kxxc4/luuACT3kLHPZE95/Lz73F+n613IVon4viNxIf7MeI/cIRU= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1705880479; c=relaxed/simple; bh=nsGSM8QjjuQkgjDooHxLYWFJF0N1Fej0z4Fu2RC9vLM=; h=From:To:Subject:Date:Message-Id:MIME-Version; b=Y6/I8/xdtdQ+EC9S8eFSIeBkOP4LgabDcI7+RfoLDJ3RAG5ePQ29cbLVtFDNnWiuHnWg5cMPzKqZM0luvub4ofBeKRuVLfiHuFWGHRjcit3adK6dF6tVpk+Q2VpVFjNdCzDbp4Vq+pRzslkv4D7a1qrXIQYuD2Qb+svs8YghN2s= ARC-Authentication-Results: i=1; server2.sourceware.org Received: from csb.redhat.com (deer0x03.wildebeest.org [172.31.17.133]) (using TLSv1.2 with cipher ADH-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by gnu.wildebeest.org (Postfix) with ESMTPSA id 7FF54302BBEA; Mon, 22 Jan 2024 00:41:16 +0100 (CET) Received: by csb.redhat.com (Postfix, from userid 10916) id 5DA58CEF2C; Mon, 22 Jan 2024 00:41:16 +0100 (CET) From: Mark Wielaard To: binutils@sourceware.org Cc: Mark Wielaard Subject: [PATCH] binutils: Fix calloc argument order in coffgrok.c Date: Mon, 22 Jan 2024 00:41:12 +0100 Message-Id: <20240121234112.579191-1-mark@klomp.org> X-Mailer: git-send-email 2.39.3 MIME-Version: 1.0 X-Spam-Status: No, score=-9.4 required=5.0 tests=BAYES_00, GIT_PATCH_0, JMQ_SPF_NEUTRAL, KAM_DMARC_STATUS, SPF_HELO_NONE, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: binutils@sourceware.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Binutils mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: binutils-bounces+ouuuleilei=gmail.com@sourceware.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1788745338673580335 X-GMAIL-MSGID: 1788745338673580335 GCC 14 will warn about calling calloc with swapped size and count arguments. binutils-gdb/binutils/coffgrok.c: In function ‘do_sections_p1’: binutils-gdb/binutils/coffgrok.c:116:72: error: ‘xcalloc’ sizes specified with ‘sizeof’ in the earlier argument and not in the later argument [-Werror=calloc-transposed-args] 116 | struct coff_section *all = (struct coff_section *) (xcalloc (sizeof (struct coff_section), | ^~~~~~ binutils-gdb/binutils/coffgrok.c:116:72: note: earlier argument should specify number of elements, later size of each element binutils/ * coffgrok.c (empty_scope): Swap xcalloc arguments. (empty_symbol): Likewise. (do_lines): Likewise. (doit): Likewise. (coff_grok): Likewise. --- binutils/coffgrok.c | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/binutils/coffgrok.c b/binutils/coffgrok.c index 4373477ac72..f52e178be57 100644 --- a/binutils/coffgrok.c +++ b/binutils/coffgrok.c @@ -65,13 +65,13 @@ static bfd * abfd; static struct coff_scope * empty_scope (void) { - return (struct coff_scope *) (xcalloc (sizeof (struct coff_scope), 1)); + return (struct coff_scope *) (xcalloc (1, sizeof (struct coff_scope))); } static struct coff_symbol * empty_symbol (void) { - return (struct coff_symbol *) (xcalloc (sizeof (struct coff_symbol), 1)); + return (struct coff_symbol *) (xcalloc (1, sizeof (struct coff_symbol))); } static void @@ -279,7 +279,7 @@ do_where (unsigned int i) static struct coff_line * do_lines (int i, char *name ATTRIBUTE_UNUSED) { - struct coff_line *res = (struct coff_line *) xcalloc (sizeof (struct coff_line), 1); + struct coff_line *res = (struct coff_line *) xcalloc (1, sizeof (struct coff_line)); asection *s; unsigned int l; @@ -316,8 +316,8 @@ do_lines (int i, char *name ATTRIBUTE_UNUSED) /* Add two extra records, one for the prologue and one for the epilogue. */ c += 1; res->nlines = c; - res->lines = (int *) (xcalloc (sizeof (int), c)); - res->addresses = (int *) (xcalloc (sizeof (int), c)); + res->lines = (int *) (xcalloc (c, sizeof (int))); + res->addresses = (int *) (xcalloc (c, sizeof (int))); res->lines[0] = start_line; res->addresses[0] = rawsyms[i].u.syment.n_value - s->vma; for (c = 0; @@ -725,7 +725,7 @@ doit (void) struct coff_sfile *n = (struct coff_sfile *) xmalloc (sizeof (struct coff_sfile)); - n->section = (struct coff_isection *) xcalloc (sizeof (struct coff_isection), abfd->section_count + 1); + n->section = (struct coff_isection *) xcalloc (abfd->section_count + 1, sizeof (struct coff_isection)); cur_sfile = n; n->name = N(sym); n->next = 0; @@ -878,7 +878,8 @@ coff_grok (bfd *inabfd) bfd_fatal (bfd_get_filename (abfd)); rawsyms = obj_raw_syments (abfd); rawcount = obj_raw_syment_count (abfd); - tindex = (struct coff_symbol **) (xcalloc (sizeof (struct coff_symbol *), rawcount)); + tindex = (struct coff_symbol **) (xcalloc (rawcount, + sizeof (struct coff_symbol *))); p = doit (); return p;