* lib/calloc.c: Include stdckdint.h, xalloc-oversized.h.
(rpl_calloc): Use ckd_mul instead of xalloc_oversized.
* modules/calloc-gnu, modules/calloc-posix:
(Depends-on): Depend on stdckdint, not xalloc-oversized.
---
 ChangeLog            | 6 ++++++
 lib/calloc.c         | 6 +++---
 modules/calloc-gnu   | 2 +-
 modules/calloc-posix | 2 +-
 4 files changed, 11 insertions(+), 5 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index a2b5a45e3e..af6fce7f00 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,11 @@
 2024-11-04  Paul Eggert  <egg...@cs.ucla.edu>
 
+       calloc: depend on stdckdint not xalloc-oversized
+       * lib/calloc.c: Include stdckdint.h, xalloc-oversized.h.
+       (rpl_calloc): Use ckd_mul instead of xalloc_oversized.
+       * modules/calloc-gnu, modules/calloc-posix:
+       (Depends-on): Depend on stdckdint, not xalloc-oversized.
+
        malloc etc. tests: use volatile more consistently
        Typically it’s ineffective to use ‘void *volatile p’
        when testing malloc and similar functions, as the compiler
diff --git a/lib/calloc.c b/lib/calloc.c
index 81dfd3efb5..801b672078 100644
--- a/lib/calloc.c
+++ b/lib/calloc.c
@@ -23,8 +23,7 @@
 #include <stdlib.h>
 
 #include <errno.h>
-
-#include "xalloc-oversized.h"
+#include <stdckdint.h>
 
 /* Call the system's calloc below.  */
 #undef calloc
@@ -38,7 +37,8 @@ rpl_calloc (size_t n, size_t s)
   if (n == 0 || s == 0)
     n = s = 1;
 
-  if (xalloc_oversized (n, s))
+  ptrdiff_t signed_n;
+  if (ckd_mul (&signed_n, n, s))
     {
       errno = ENOMEM;
       return NULL;
diff --git a/modules/calloc-gnu b/modules/calloc-gnu
index f3fb393e53..63f498f0d4 100644
--- a/modules/calloc-gnu
+++ b/modules/calloc-gnu
@@ -8,7 +8,7 @@ m4/calloc.m4
 Depends-on:
 calloc-posix
 extensions-aix
-xalloc-oversized     [test $REPLACE_CALLOC_FOR_CALLOC_GNU = 1]
+stdckdint            [test $REPLACE_CALLOC_FOR_CALLOC_GNU = 1]
 
 configure.ac:
 gl_FUNC_CALLOC_GNU
diff --git a/modules/calloc-posix b/modules/calloc-posix
index 5bf5ab8676..e455296d75 100644
--- a/modules/calloc-posix
+++ b/modules/calloc-posix
@@ -7,8 +7,8 @@ m4/calloc.m4
 m4/malloc.m4
 
 Depends-on:
+stdckdint            [test $REPLACE_CALLOC_FOR_CALLOC_POSIX = 1]
 stdlib
-xalloc-oversized     [test $REPLACE_CALLOC_FOR_CALLOC_POSIX = 1]
 
 configure.ac:
 gl_FUNC_CALLOC_POSIX
-- 
2.43.0


Reply via email to