public inbox for binutils@sourceware.org
 help / color / mirror / Atom feed
* [PATCH] binutils: Fix calloc argument order in coffgrok.c
@ 2024-01-21 23:41 Mark Wielaard
  2024-01-22 17:16 ` Nick Clifton
  0 siblings, 1 reply; 2+ messages in thread
From: Mark Wielaard @ 2024-01-21 23:41 UTC (permalink / raw)
  To: binutils; +Cc: Mark Wielaard

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;
-- 
2.39.3


^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH] binutils: Fix calloc argument order in coffgrok.c
  2024-01-21 23:41 [PATCH] binutils: Fix calloc argument order in coffgrok.c Mark Wielaard
@ 2024-01-22 17:16 ` Nick Clifton
  0 siblings, 0 replies; 2+ messages in thread
From: Nick Clifton @ 2024-01-22 17:16 UTC (permalink / raw)
  To: Mark Wielaard, binutils

Hi Mark,

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

> binutils/
> 
> 	* coffgrok.c (empty_scope): Swap xcalloc arguments.
> 	(empty_symbol): Likewise.
> 	(do_lines): Likewise.
> 	(doit): Likewise.
> 	(coff_grok): Likewise.

Approved - please apply.

Cheers
   Nick


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2024-01-22 17:16 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-01-21 23:41 [PATCH] binutils: Fix calloc argument order in coffgrok.c Mark Wielaard
2024-01-22 17:16 ` Nick Clifton

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).