public inbox for elfutils@sourceware.org
 help / color / mirror / Atom feed
* [PATCH] tests: fix build against upcoming `gcc-14` (`-Werror=calloc-transposed-args`)
@ 2023-12-21  9:23 Sergei Trofimovich
  2023-12-21 21:23 ` Mark Wielaard
  0 siblings, 1 reply; 2+ messages in thread
From: Sergei Trofimovich @ 2023-12-21  9:23 UTC (permalink / raw)
  To: elfutils-devel; +Cc: Sergei Trofimovich

`gcc-14` added a new `-Wcalloc-transposed-args` warning recently. It
detected minor infelicity in `calloc()` API usage in `elfutils`:

    elfstrmerge.c: In function 'main':
    elfstrmerge.c:450:32: error:
      'calloc' sizes specified with 'sizeof' in the earlier argument and not in the later argument [-Werror=calloc-transposed-args]
      450 |   newscnbufs = calloc (sizeof (void *), newshnums);
          |                                ^~~~
    elfstrmerge.c:450:32: note: earlier argument should specify number of elements, later size of each element

Signed-off-by: Sergei Trofimovich <slyich@gmail.com>
---
 tests/elfstrmerge.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/tests/elfstrmerge.c b/tests/elfstrmerge.c
index 56350bb9..4eb58bbb 100644
--- a/tests/elfstrmerge.c
+++ b/tests/elfstrmerge.c
@@ -447,7 +447,7 @@ main (int argc, char **argv)
     }
 
   newshnums = shdrnum - 1;
-  newscnbufs = calloc (sizeof (void *), newshnums);
+  newscnbufs = calloc (newshnums, sizeof (void *));
   if (newscnbufs == NULL)
     fail_errno ("Couldn't allocate memory for new section buffers", NULL);
 
-- 
2.42.0


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

* Re: [PATCH] tests: fix build against upcoming `gcc-14` (`-Werror=calloc-transposed-args`)
  2023-12-21  9:23 [PATCH] tests: fix build against upcoming `gcc-14` (`-Werror=calloc-transposed-args`) Sergei Trofimovich
@ 2023-12-21 21:23 ` Mark Wielaard
  0 siblings, 0 replies; 2+ messages in thread
From: Mark Wielaard @ 2023-12-21 21:23 UTC (permalink / raw)
  To: Sergei Trofimovich, elfutils-devel

Hi Sergei,

On Thu, 2023-12-21 at 09:23 +0000, Sergei Trofimovich wrote:
> `gcc-14` added a new `-Wcalloc-transposed-args` warning recently. It
> detected minor infelicity in `calloc()` API usage in `elfutils`:
> 
>     elfstrmerge.c: In function 'main':
>     elfstrmerge.c:450:32: error:
>       'calloc' sizes specified with 'sizeof' in the earlier argument and not in the later argument [-Werror=calloc-transposed-args]
>       450 |   newscnbufs = calloc (sizeof (void *), newshnums);
>           |                                ^~~~
>     elfstrmerge.c:450:32: note: earlier argument should specify number of elements, later size of each element
> 

Thanks, looks good. Pushed.

Cheers,

Mark

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

end of thread, other threads:[~2023-12-21 21:23 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-12-21  9:23 [PATCH] tests: fix build against upcoming `gcc-14` (`-Werror=calloc-transposed-args`) Sergei Trofimovich
2023-12-21 21:23 ` Mark Wielaard

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