]> Savannah Git Hosting - gnulib.git/commitdiff
stdckdint: prefer to intprops when easy
authorPaul Eggert <eggert@cs.ucla.edu>
Wed, 10 Aug 2022 06:20:49 +0000 (23:20 -0700)
committerPaul Eggert <eggert@cs.ucla.edu>
Wed, 10 Aug 2022 07:22:09 +0000 (00:22 -0700)
stdckdint.h is part of draft C23 and therefore is more likely
to be familiar to programmers in the future, so prefer it to
intprops.h in files that don’t need non-_WRAPV intprops.h macros.
* lib/alignalloc.c, lib/backupfile.c, lib/fnmatch.c, lib/fnmatch_loop.c:
* lib/group-member.c, lib/malloca.c, lib/posixtm.c, lib/reallocarray.c:
* lib/xmalloc.c:
For files that can use stdckdint.h just as easily as intprops.h,
include the former instead of the latter, and use the former’s
ckd_* macros instead of the latter’s *_WRAPV macros.
* modules/alignalloc, modules/backup-rename, modules/backupfile:
* modules/fnmatch, modules/group-member, modules/malloca:
* modules/posixtm, modules/reallocarray:
* modules/relocatable-prog-wrapper, modules/xalloc:
Depend on stdckdint instead of intprops.

20 files changed:
ChangeLog
lib/alignalloc.c
lib/backupfile.c
lib/fnmatch.c
lib/fnmatch_loop.c
lib/group-member.c
lib/malloca.c
lib/posixtm.c
lib/reallocarray.c
lib/xmalloc.c
modules/alignalloc
modules/backup-rename
modules/backupfile
modules/fnmatch
modules/group-member
modules/malloca
modules/posixtm
modules/reallocarray
modules/relocatable-prog-wrapper
modules/xalloc

index 20c25c902a0d3335f5b0223fccdb772d391daede..5293fc104f8f18f315f3160fb7eb4b6ac4b52442 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,21 @@
 2022-08-09  Paul Eggert  <eggert@cs.ucla.edu>
 
+       stdckdint: prefer to intprops when easy
+       stdckdint.h is part of draft C23 and therefore is more likely
+       to be familiar to programmers in the future, so prefer it to
+       intprops.h in files that don’t need non-_WRAPV intprops.h macros.
+       * lib/alignalloc.c, lib/backupfile.c, lib/fnmatch.c, lib/fnmatch_loop.c:
+       * lib/group-member.c, lib/malloca.c, lib/posixtm.c, lib/reallocarray.c:
+       * lib/xmalloc.c:
+       For files that can use stdckdint.h just as easily as intprops.h,
+       include the former instead of the latter, and use the former’s
+       ckd_* macros instead of the latter’s *_WRAPV macros.
+       * modules/alignalloc, modules/backup-rename, modules/backupfile:
+       * modules/fnmatch, modules/group-member, modules/malloca:
+       * modules/posixtm, modules/reallocarray:
+       * modules/relocatable-prog-wrapper, modules/xalloc:
+       Depend on stdckdint instead of intprops.
+
        stdckdint: new module
        This supports draft C23 <stdckdint.h>.
        * doc/posix-headers/stdckdint.texi:
index 03988f11a4b8d89b7e51ff67ed8e503c7e656e04..1884394e3cce87ef6b2251ac13726a60e43344e7 100644 (file)
@@ -24,8 +24,8 @@
 
 #include <limits.h>
 #include <stdalign.h>
+#include <stdckdint.h>
 #include <stdint.h>
-#include "intprops.h"
 #include "verify.h"
 
 #if !ALIGNALLOC_VIA_ALIGNED_ALLOC
@@ -82,7 +82,7 @@ alignalloc (idx_t alignment, idx_t size)
 
   size_t malloc_size;
   unsigned char *q;
-  if (INT_ADD_WRAPV (size, alignment, &malloc_size)
+  if (ckd_add (&malloc_size, size, alignment)
       || ! (q = malloc (malloc_size)))
     {
       errno = ENOMEM;
index d9f465a3e0eaa8bdd0764247dbf285a5b14455c8..b2ab67847ac0cfb94d4b8666b8c66c0ef94bd8f2 100644 (file)
@@ -26,6 +26,7 @@
 #include <errno.h>
 #include <fcntl.h>
 #include <stdbool.h>
+#include <stdckdint.h>
 #include <stdint.h>
 #include <stdlib.h>
 #include <string.h>
@@ -34,7 +35,6 @@
 #include "attribute.h"
 #include "basename-lgpl.h"
 #include "ialloc.h"
-#include "intprops.h"
 #include "opendirat.h"
 #include "renameatu.h"
 
@@ -272,7 +272,7 @@ numbered_backup (int dir_fd, char **buffer, idx_t buffer_size, idx_t filelen,
       if (buffer_size < new_buffer_size)
         {
           idx_t grown;
-          if (! INT_ADD_WRAPV (new_buffer_size, new_buffer_size >> 1, &grown))
+          if (! ckd_add (&grown, new_buffer_size, new_buffer_size >> 1))
             new_buffer_size = grown;
           char *new_buf = irealloc (buf, new_buffer_size);
           if (!new_buf)
index b33a127d9802be15eeafef4622e63aac709bef8e..45e326902defe606941027577a7f14c00bc6847e 100644 (file)
@@ -30,6 +30,7 @@
 #include <errno.h>
 #include <ctype.h>
 #include <string.h>
+#include <stdckdint.h>
 #include <stdlib.h>
 #if defined _LIBC || HAVE_ALLOCA
 # include <alloca.h>
@@ -73,7 +74,6 @@ extern int fnmatch (const char *pattern, const char *string, int flags);
 # include "attribute.h"
 #endif
 
-#include <intprops.h>
 #include <flexmember.h>
 
 #ifdef _LIBC
index e635953758b7f6b42d27fece17b1ce2cda1a37cb..1b16de99b697c8572421735620278fda00cba1bb 100644 (file)
@@ -1039,8 +1039,8 @@ EXT (INT opt, const CHAR *pattern, const CHAR *string, const CHAR *string_end,
             idx_t slen = FLEXSIZEOF (struct patternlist, str, 0);             \
             idx_t new_used = alloca_used + slen;                              \
             idx_t plensize;                                                   \
-            if (INT_MULTIPLY_WRAPV (plen, sizeof (CHAR), &plensize)           \
-                || INT_ADD_WRAPV (new_used, plensize, &new_used))             \
+            if (ckd_mul (&plensize, plen, sizeof (CHAR), &plensize)           \
+                || ckd_add (&new_used, new_used, plensize))                   \
               {                                                               \
                 retval = -2;                                                  \
                 goto out;                                                     \
index 480a12616a2d9f0791d87d484753bf43bec8d327..cd43f36f4eb64bfa8d7937b243fb1fa52f860756 100644 (file)
 /* Specification.  */
 #include <unistd.h>
 
+#include <stdckdint.h>
 #include <stdio.h>
 #include <sys/types.h>
 #include <stdlib.h>
 
-#include "intprops.h"
-
 /* Most processes have no more than this many groups, and for these
    processes we can avoid using malloc.  */
 enum { GROUPBUF_SIZE = 100 };
@@ -54,7 +53,7 @@ get_group_info (struct group_info *gi)
     {
       int n_group_slots = getgroups (0, NULL);
       size_t nbytes;
-      if (! INT_MULTIPLY_WRAPV (n_group_slots, sizeof *gi->group, &nbytes))
+      if (! ckd_mul (&nbytes, n_group_slots, sizeof *gi->group))
         {
           gi->group = malloc (nbytes);
           if (gi->group)
index e7beaaf066ec8427850e33a3aaae2d139d7d76fd..183783a71045e8c2a8e4becb452bd657b4d720ea 100644 (file)
@@ -21,8 +21,9 @@
 /* Specification.  */
 #include "malloca.h"
 
+#include <stdckdint.h>
+
 #include "idx.h"
-#include "intprops.h"
 #include "verify.h"
 
 /* The speed critical point in this file is freea() applied to an alloca()
@@ -50,17 +51,16 @@ mmalloca (size_t n)
   uintptr_t alignment2_mask = 2 * sa_alignment_max - 1;
   int plus = sizeof (small_t) + alignment2_mask;
   idx_t nplus;
-  if (!INT_ADD_WRAPV (n, plus, &nplus) && !xalloc_oversized (nplus, 1))
+  if (!ckd_add (&nplus, n, plus) && !xalloc_oversized (nplus, 1))
     {
       char *mem = (char *) malloc (nplus);
 
       if (mem != NULL)
         {
           uintptr_t umem = (uintptr_t)mem, umemplus;
-          /* The INT_ADD_WRAPV avoids signed integer overflow on
+          /* The ckd_add avoids signed integer overflow on
              theoretical platforms where UINTPTR_MAX <= INT_MAX.  */
-          INT_ADD_WRAPV (umem, sizeof (small_t) + sa_alignment_max - 1,
-                         &umemplus);
+          ckd_add (&umemplus, umem, sizeof (small_t) + sa_alignment_max - 1);
           idx_t offset = ((umemplus & ~alignment2_mask)
                           + sa_alignment_max - umem);
           void *vp = mem + offset;
index b00cef42fd4043b689867ce65ff9758fcbcf11ea..3c323782fa2c5c84e021674bb7a98b4458021606 100644 (file)
@@ -24,9 +24,9 @@
 
 #include "c-ctype.h"
 #include "idx.h"
-#include "intprops.h"
 #include "verify.h"
 
+#include <stdckdint.h>
 #include <string.h>
 
 /*
@@ -191,7 +191,7 @@ posixtime (time_t *p, const char *s, unsigned int syntax_bits)
              | (tm0.tm_min ^ tm1.tm_min)
              | (tm0.tm_sec ^ tm1.tm_sec)))
         {
-          if (INT_ADD_WRAPV (t, leapsec, &t))
+          if (ckd_add (&t, t, leapsec))
             return false;
           *p = t;
           return true;
index bc4cba4b61282b6bbc7b022fd45a7bcef05b4aa9..70c1b478727b342b4528109c7a0068c557dd2865 100644 (file)
 
 #include <config.h>
 
+#include <stdckdint.h>
 #include <stdlib.h>
 #include <errno.h>
 
-#include "intprops.h"
-
 void *
 reallocarray (void *ptr, size_t nmemb, size_t size)
 {
   size_t nbytes;
-  if (INT_MULTIPLY_WRAPV (nmemb, size, &nbytes))
+  if (ckd_mul (&nbytes, nmemb, size))
     {
       errno = ENOMEM;
       return NULL;
index 993c1eeb75ba19313e0e43f80186c99ccfa58b1d..3c3cb20799692018cdc90f8213193f8f04d22879 100644 (file)
@@ -22,9 +22,9 @@
 #include "xalloc.h"
 
 #include "ialloc.h"
-#include "intprops.h"
 #include "minmax.h"
 
+#include <stdckdint.h>
 #include <stdlib.h>
 #include <string.h>
 
@@ -195,7 +195,7 @@ x2nrealloc (void *p, size_t *pn, size_t s)
   else
     {
       /* Set N = floor (1.5 * N) + 1 to make progress even if N == 0.  */
-      if (INT_ADD_WRAPV (n, (n >> 1) + 1, &n))
+      if (ckd_add (&n, n, (n >> 1) + 1))
         xalloc_die ();
     }
 
@@ -236,7 +236,7 @@ xpalloc (void *pa, idx_t *pn, idx_t n_incr_min, ptrdiff_t n_max, idx_t s)
      N_MAX, and what the C language can represent safely.  */
 
   idx_t n;
-  if (INT_ADD_WRAPV (n0, n0 >> 1, &n))
+  if (ckd_add (&n, n0, n0 >> 1))
     n = IDX_MAX;
   if (0 <= n_max && n_max < n)
     n = n_max;
@@ -251,7 +251,7 @@ xpalloc (void *pa, idx_t *pn, idx_t n_incr_min, ptrdiff_t n_max, idx_t s)
   size_t nbytes;
 #endif
   idx_t adjusted_nbytes
-    = (INT_MULTIPLY_WRAPV (n, s, &nbytes)
+    = (ckd_mul (&nbytes, n, s)
        ? MIN (IDX_MAX, SIZE_MAX)
        : nbytes < DEFAULT_MXFAST ? DEFAULT_MXFAST : 0);
   if (adjusted_nbytes)
@@ -263,9 +263,9 @@ xpalloc (void *pa, idx_t *pn, idx_t n_incr_min, ptrdiff_t n_max, idx_t s)
   if (! pa)
     *pn = 0;
   if (n - n0 < n_incr_min
-      && (INT_ADD_WRAPV (n0, n_incr_min, &n)
+      && (ckd_add (&n, n0, n_incr_min)
           || (0 <= n_max && n_max < n)
-          || INT_MULTIPLY_WRAPV (n, s, &nbytes)))
+          || ckd_mul (&nbytes, n, s)))
     xalloc_die ();
   pa = xrealloc (pa, nbytes);
   *pn = n;
index 68c1b14cd4e5ee28cd4dfeac29131e6c48947a7b..42ca672bc2110fccf50e47c4d5119e4e6fa94bbf 100644 (file)
@@ -10,9 +10,9 @@ Depends-on:
 extensions
 extern-inline
 idx
-intprops
 posix_memalign
 stdalign
+stdckdint
 stdint
 verify
 
index 245350a4df753461d04a0a05f9b54a3d20a02941..54a8270a90567e58d6a23eab239470fdd41a2e09 100644 (file)
@@ -17,12 +17,12 @@ closedir
 d-ino
 fcntl-h
 ialloc
-intprops
 memcmp
 opendirat
 readdir
 renameatu
 stdbool
+stdckdint
 stdint
 xalloc-oversized
 
index 3d06da9ed4073db6354ce856ce183f65585bb521..804e62d48c6b8eaa6da0b6a9da96415881157dd4 100644 (file)
@@ -17,13 +17,13 @@ closedir
 d-ino
 fcntl-h
 ialloc
-intprops
 memcmp
 opendirat
 readdir
 realloc-gnu
 renameatu
 stdbool
+stdckdint
 stdint
 xalloc-die
 
index 37ebfe2250d96c0a4bfead0fd0b87ba58ed0ef0a..7de95c565adfe8f5a627b94e88ea11cfde85948c 100644 (file)
@@ -15,11 +15,11 @@ btowc           [test $HAVE_FNMATCH = 0 || test $REPLACE_FNMATCH = 1]
 builtin-expect  [test $HAVE_FNMATCH = 0 || test $REPLACE_FNMATCH = 1]
 flexmember      [test $HAVE_FNMATCH = 0 || test $REPLACE_FNMATCH = 1]
 idx             [test $HAVE_FNMATCH = 0 || test $REPLACE_FNMATCH = 1]
-intprops        [test $HAVE_FNMATCH = 0 || test $REPLACE_FNMATCH = 1]
 isblank         [test $HAVE_FNMATCH = 0 || test $REPLACE_FNMATCH = 1]
 iswctype        [test $HAVE_FNMATCH = 0 || test $REPLACE_FNMATCH = 1]
 libc-config     [test $HAVE_FNMATCH = 0 || test $REPLACE_FNMATCH = 1]
 stdbool         [test $HAVE_FNMATCH = 0 || test $REPLACE_FNMATCH = 1]
+stdckdint       [test $HAVE_FNMATCH = 0 || test $REPLACE_FNMATCH = 1]
 strnlen         [test $HAVE_FNMATCH = 0 || test $REPLACE_FNMATCH = 1]
 wchar           [test $HAVE_FNMATCH = 0 || test $REPLACE_FNMATCH = 1]
 wctype-h        [test $HAVE_FNMATCH = 0 || test $REPLACE_FNMATCH = 1]
index c08e786e0a06f6eeeb37cab3588d4568e023c54f..d84b751c0c5e642834a04029ff0f06dedd5274d4 100644 (file)
@@ -9,8 +9,8 @@ Depends-on:
 unistd
 extensions
 getgroups        [test $HAVE_GROUP_MEMBER = 0]
-intprops         [test $HAVE_GROUP_MEMBER = 0]
 realloc-gnu      [test $HAVE_GROUP_MEMBER = 0]
+stdckdint        [test $HAVE_GROUP_MEMBER = 0]
 
 configure.ac:
 gl_FUNC_GROUP_MEMBER
index 346d33251a74840c09590adaa4ea7395b245b07c..9c279c45f13cafceb00b09726923695dfed44fe3 100644 (file)
@@ -10,7 +10,7 @@ m4/eealloc.m4
 Depends-on:
 alloca-opt
 idx
-intprops
+stdckdint
 stdint
 verify
 xalloc-oversized
index 5ecc016ae94d50da8e330f706842302b9ecf0f36..f302efac63dcf6b424e7834890bd6625b42f67d6 100644 (file)
@@ -9,9 +9,9 @@ m4/posixtm.m4
 Depends-on:
 c-ctype
 idx
-intprops
 mktime
 stdbool
+stdckdint
 verify
 
 configure.ac:
index 9d2db6b888712c1fbc0c4c8aabf696300bf8797f..380434870ee5d499099d3b09e4f7c96f7d94e6e1 100644 (file)
@@ -8,8 +8,8 @@ m4/reallocarray.m4
 
 Depends-on:
 extensions
-intprops       [test $HAVE_REALLOCARRAY = 0 || test $REPLACE_REALLOCARRAY = 1]
 realloc-gnu    [test $HAVE_REALLOCARRAY = 0 || test $REPLACE_REALLOCARRAY = 1]
+stdckdint      [test $HAVE_REALLOCARRAY = 0 || test $REPLACE_REALLOCARRAY = 1]
 stdlib
 
 configure.ac:
index fa56916217866fb8b00dec813bb4413608770a7b..9b9d9c3abe6a10937aa9a59d066845ed4508f691 100644 (file)
@@ -67,6 +67,7 @@ ssize_t
 stdalign
 stdbool
 stddef
+stdckdint
 stdint
 stdlib
 string
index 0fc3836c2cae2f0289d5a5982d8388dceba32209..15059bf47fa12aee11b8a941f7952dca014ca007 100644 (file)
@@ -12,11 +12,11 @@ calloc-gnu
 extern-inline
 ialloc
 idx
-intprops
 malloc-gnu
 minmax
 realloc-gnu
 reallocarray
+stdckdint
 stdint
 xalloc-die