Building a testdir with a GCC 15 snapshot, I see these warnings:

../../gllib/gc-gnulib.c:177:24: warning: 'calloc' sizes specified with 'sizeof' 
in the earlier argument and not in the later argument
../../gllib/gc-gnulib.c:566:24: warning: 'calloc' sizes specified with 'sizeof' 
in the earlier argument and not in the later argument
../../gllib/gc-gnulib.c:637:37: warning: 'calloc' sizes specified with 'sizeof' 
in the earlier argument and not in the later argument

Since the first argument of calloc() is meant to be the number of elements
to allocate and the second argument is meant to be the size of each element,
and since here each element is a _gc_cipher_ctx or _gc_hash_ctx, the
warning makes sense. Although the implementation of calloc() is written in
such a way that it does not make a practical difference. But for fwrite() it
does make a difference.


2025-04-02  Bruno Haible  <br...@clisp.org>

        crypto/gc: Silence some -Wcalloc-transposed-args warnings.
        * lib/gc-gnulib.c (gc_cipher_open, gc_hash_open, gc_hash_clone): Swap
        the arguments of calloc().

diff --git a/lib/gc-gnulib.c b/lib/gc-gnulib.c
index 11870adcc5..4eaf9a7656 100644
--- a/lib/gc-gnulib.c
+++ b/lib/gc-gnulib.c
@@ -174,7 +174,7 @@ gc_cipher_open (Gc_cipher alg, Gc_cipher_mode mode,
   _gc_cipher_ctx *ctx;
   Gc_rc rc = GC_OK;
 
-  ctx = calloc (sizeof (*ctx), 1);
+  ctx = calloc (1, sizeof (*ctx));
   if (!ctx)
     return GC_MALLOC_ERROR;
 
@@ -563,7 +563,7 @@ gc_hash_open (Gc_hash hash, Gc_hash_mode mode, 
gc_hash_handle * outhandle)
   if (mode != 0)
     return GC_INVALID_HASH;
 
-  ctx = calloc (sizeof (*ctx), 1);
+  ctx = calloc (1, sizeof (*ctx));
   if (!ctx)
     return GC_MALLOC_ERROR;
 
@@ -634,7 +634,7 @@ gc_hash_clone (gc_hash_handle handle, gc_hash_handle * 
outhandle)
   _gc_hash_ctx *in = handle;
   _gc_hash_ctx *out;
 
-  *outhandle = out = calloc (sizeof (*out), 1);
+  *outhandle = out = calloc (1, sizeof (*out));
   if (!out)
     return GC_MALLOC_ERROR;
 




Reply via email to