public inbox for binutils@sourceware.org
 help / color / mirror / Atom feed
From: Mark Wielaard <mark@klomp.org>
To: binutils@sourceware.org
Cc: Mark Wielaard <mark@klomp.org>
Subject: [PATCH] binutils: Fix calloc argument order in srconv.c
Date: Mon, 22 Jan 2024 00:50:38 +0100	[thread overview]
Message-ID: <20240121235038.580321-1-mark@klomp.org> (raw)

GCC 14 will warn about calling calloc with swapped size and count
arguments.

binutils/srconv.c: In function ‘nints’:
binutils/srconv.c:598:36: error: ‘xcalloc’ sizes specified with ‘sizeof’ in the earlier argument and not in the later argument [-Werror=calloc-transposed-args]
  598 |   return (int *) (xcalloc (sizeof (int), x));
      |                                    ^~~
binutils/srconv.c:598:36: note: earlier argument should specify number of elements, later size of each element

binutils/

	* srconv.c (nints): Swap xcalloc arguments.
	(wr_du): Likewise.
	(wr_dus): Likewise.
---
 binutils/srconv.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/binutils/srconv.c b/binutils/srconv.c
index 1ff68fa08b0..7e22f7a0d4f 100644
--- a/binutils/srconv.c
+++ b/binutils/srconv.c
@@ -595,7 +595,7 @@ wr_dps_end (struct coff_section *section ATTRIBUTE_UNUSED,
 static int *
 nints (int x)
 {
-  return (int *) (xcalloc (sizeof (int), x));
+  return (int *) (xcalloc (x, sizeof (int)));
 }
 
 static void
@@ -1183,7 +1183,7 @@ wr_du (struct coff_ofile *p, struct coff_sfile *sfile, int n)
   du.spare = 0;
   du.unit = n;
   du.sections = p->nsections - 1;
-  du.san = (int *) xcalloc (sizeof (int), du.sections);
+  du.san = (int *) xcalloc (du.sections, sizeof (int));
   du.address = nints (du.sections);
   du.length = nints (du.sections);
 
@@ -1242,7 +1242,7 @@ wr_dus (struct coff_ofile *p ATTRIBUTE_UNUSED, struct coff_sfile *sfile)
   dus.efn = 0x1001;
   dus.ns = 1;			/* p->nsources; sac 14 jul 94 */
   dus.drb = nints (dus.ns);
-  dus.fname = (char **) xcalloc (sizeof (char *), dus.ns);
+  dus.fname = (char **) xcalloc (dus.ns, sizeof (char *));
   dus.spare = nints (dus.ns);
   dus.ndir = 0;
   /* Find the filenames.  */
-- 
2.39.3


             reply	other threads:[~2024-01-21 23:50 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-01-21 23:50 Mark Wielaard [this message]
2024-01-22 17:16 ` Nick Clifton

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20240121235038.580321-1-mark@klomp.org \
    --to=mark@klomp.org \
    --cc=binutils@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).