stdckdint: use in more modules
authorPaul Eggert <eggert@cs.ucla.edu>
Wed, 17 May 2023 19:24:07 +0000 (12:24 -0700)
committerPaul Eggert <eggert@cs.ucla.edu>
Wed, 17 May 2023 19:49:42 +0000 (12:49 -0700)
* lib/nstrftime.c (__strftime_internal):
* lib/timespec-add.c (timespec_add):
* lib/timespec-sub.c (timespec_sub):
* lib/xstrtol.c (bkm_scale):
Prefer ckd_add to INT_ADD_WRAPV etc., and include stdckdint.h.
* modules/nstrftime, modules/timespec-add, modules/timespec-sub:
* modules/xstrtol:
(Depends-on): Add stdckdint.

ChangeLog
lib/nstrftime.c
lib/stat-time.h
lib/timespec-add.c
lib/timespec-sub.c
lib/xstrtol.c
modules/nstrftime
modules/timespec-add
modules/timespec-sub
modules/xstrtol

index 36b3c65b81b73310bd7000abab0b36e6914cd34e..fc4e43a88165c6e867a4fef4f80d78c3564eb327 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,15 @@
 2023-05-17  Paul Eggert  <eggert@cs.ucla.edu>
 
+       stdckdint: use in more modules
+       * lib/nstrftime.c (__strftime_internal):
+       * lib/timespec-add.c (timespec_add):
+       * lib/timespec-sub.c (timespec_sub):
+       * lib/xstrtol.c (bkm_scale):
+       Prefer ckd_add to INT_ADD_WRAPV etc., and include stdckdint.h.
+       * modules/nstrftime, modules/timespec-add, modules/timespec-sub:
+       * modules/xstrtol:
+       (Depends-on): Add stdckdint.
+
        nstrftime: suggest to glibc how to avoid alloca
        * lib/nstrftime.c (widen) [COMPILE_WIDE]: Remove.
        (__strftime_internal) [COMPILE_WIDE): Instead of converting the
index 35a9307e1a749f4b11f37199e28fc9b6de80d1ac..2a1dd8d88d7606c08dbb633a2accda52f5acd3d1 100644 (file)
@@ -62,6 +62,7 @@ extern char *tzname[];
 #endif
 
 #include <limits.h>
+#include <stdckdint.h>
 #include <stddef.h>
 #include <stdlib.h>
 #include <string.h>
@@ -675,8 +676,8 @@ __strftime_internal (STREAM_OR_CHAR_T *s, STRFTIME_ARG (size_t maxsize)
           width = 0;
           do
             {
-              if (INT_MULTIPLY_WRAPV (width, 10, &width)
-                  || INT_ADD_WRAPV (width, *f - L_('0'), &width))
+              if (ckd_mul (&width, width, 10)
+                  || ckd_add (&width, width, *f - L_('0')))
                 width = INT_MAX;
               ++f;
             }
index af084102dae8d40b71f1f1283d3caa1297b1d500..75eb27e549d413f36a906f3fc700bcc6f322a559 100644 (file)
@@ -221,8 +221,7 @@ stat_time_normalize (int result, _GL_UNUSED struct stat *st)
             }
           ts->tv_nsec = r;
           /* Overflow is possible, as Solaris 11 stat can yield
-             tv_sec == TYPE_MINIMUM (time_t) && tv_nsec == -1000000000.
-             INT_ADD_WRAPV is OK, since time_t is signed on Solaris.  */
+             tv_sec == TYPE_MINIMUM (time_t) && tv_nsec == -1000000000.  */
           if (ckd_add (&ts->tv_sec, q, ts->tv_sec))
             {
               errno = EOVERFLOW;
index cb3017803b413ffad5e4023fea17ef9bd315d278..38c4dfc24c2dbab6a6ee7418cb40d5cd053d79db 100644 (file)
@@ -23,6 +23,7 @@
 #include <config.h>
 #include "timespec.h"
 
+#include <stdckdint.h>
 #include "intprops.h"
 
 struct timespec
@@ -38,7 +39,7 @@ timespec_add (struct timespec a, struct timespec b)
     {
       rns = nsd;
       time_t bs1;
-      if (!INT_ADD_WRAPV (bs, 1, &bs1))
+      if (!ckd_add (&bs1, bs, 1))
         bs = bs1;
       else if (rs < 0)
         rs++;
@@ -46,7 +47,7 @@ timespec_add (struct timespec a, struct timespec b)
         goto high_overflow;
     }
 
-  if (INT_ADD_WRAPV (rs, bs, &rs))
+  if (ckd_add (&rs, rs, bs))
     {
       if (bs < 0)
         {
index 822c2831089b084bbfd29b1c125beb11df74ff00..f8052400410210d78104ca816c0b950f7f109d87 100644 (file)
@@ -24,6 +24,7 @@
 #include <config.h>
 #include "timespec.h"
 
+#include <stdckdint.h>
 #include "intprops.h"
 
 struct timespec
@@ -38,7 +39,7 @@ timespec_sub (struct timespec a, struct timespec b)
     {
       rns = ns + TIMESPEC_HZ;
       time_t bs1;
-      if (!INT_ADD_WRAPV (bs, 1, &bs1))
+      if (!ckd_add (&bs1, bs, 1))
         bs = bs1;
       else if (- TYPE_SIGNED (time_t) < rs)
         rs--;
@@ -46,7 +47,7 @@ timespec_sub (struct timespec a, struct timespec b)
         goto low_overflow;
     }
 
-  if (INT_SUBTRACT_WRAPV (rs, bs, &rs))
+  if (ckd_sub (&rs, rs, bs))
     {
       if (0 < bs)
         {
index 9695b42ee9c07beb778cbb18740b8b0a28ba67f3..6a8e042e81d547cc4431b175ab1de3f1c7abfa51 100644 (file)
@@ -37,6 +37,7 @@
 #include <ctype.h>
 #include <errno.h>
 #include <limits.h>
+#include <stdckdint.h>
 #include <stdlib.h>
 #include <string.h>
 
@@ -51,7 +52,7 @@ static strtol_error
 bkm_scale (__strtol_t *x, int scale_factor)
 {
   __strtol_t scaled;
-  if (INT_MULTIPLY_WRAPV (*x, scale_factor, &scaled))
+  if (ckd_mul (&scaled, *x, scale_factor))
     {
       *x = *x < 0 ? TYPE_MINIMUM (__strtol_t) : TYPE_MAXIMUM (__strtol_t);
       return LONGINT_OVERFLOW;
index a24af8dcb3275171bf85acdd6e6f33c6b87b13ac..fdaf7913d3397c9c3db7792cf38e6896802a9730 100644 (file)
@@ -15,6 +15,7 @@ extensions
 intprops
 libc-config
 stdbool
+stdckdint
 time_rz
 
 configure.ac:
index 68050bf856aa138e67dbe8ddca5a85bd8c7af888..45daf6e26b443a0494332c3bce4bc42c795f40ff 100644 (file)
@@ -7,6 +7,7 @@ lib/timespec-add.c
 Depends-on:
 c99
 intprops
+stdckdint
 timespec
 
 configure.ac:
index f442ceafbb3c4da328e968573eba0678fb7d93fd..d7316a5c9c523d5e77ac7072043b3d678860e897 100644 (file)
@@ -7,6 +7,7 @@ lib/timespec-sub.c
 Depends-on:
 c99
 intprops
+stdckdint
 timespec
 
 configure.ac:
index 137cc1f5abc14f87f911b156079b3adc01a21747..c9712dee0c7f1ee7a563528db04823d0c1557895 100644 (file)
@@ -10,6 +10,7 @@ m4/xstrtol.m4
 Depends-on:
 assure
 intprops
+stdckdint
 stdint
 
 configure.ac: