diff options
author | Paul Eggert <eggert@cs.ucla.edu> | 2023-05-17 12:24:07 -0700 |
---|---|---|
committer | Paul Eggert <eggert@cs.ucla.edu> | 2023-05-17 12:49:42 -0700 |
commit | d959e39cbd54b4755525bcbd907a3402843dabba (patch) | |
tree | 0ac67f178f429d0fb7d6dd1673c98ab40d82238f /lib | |
parent | 0a4e0cab0dbb2a70e26484e32378784b5106ae08 (diff) | |
download | gnulib-d959e39cbd54b4755525bcbd907a3402843dabba.tar.gz |
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.
Diffstat (limited to 'lib')
-rw-r--r-- | lib/nstrftime.c | 5 | ||||
-rw-r--r-- | lib/stat-time.h | 3 | ||||
-rw-r--r-- | lib/timespec-add.c | 5 | ||||
-rw-r--r-- | lib/timespec-sub.c | 5 | ||||
-rw-r--r-- | lib/xstrtol.c | 3 |
5 files changed, 12 insertions, 9 deletions
diff --git a/lib/nstrftime.c b/lib/nstrftime.c index 35a9307e1a..2a1dd8d88d 100644 --- a/lib/nstrftime.c +++ b/lib/nstrftime.c @@ -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; } diff --git a/lib/stat-time.h b/lib/stat-time.h index af084102da..75eb27e549 100644 --- a/lib/stat-time.h +++ b/lib/stat-time.h @@ -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; diff --git a/lib/timespec-add.c b/lib/timespec-add.c index cb3017803b..38c4dfc24c 100644 --- a/lib/timespec-add.c +++ b/lib/timespec-add.c @@ -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) { diff --git a/lib/timespec-sub.c b/lib/timespec-sub.c index 822c283108..f805240041 100644 --- a/lib/timespec-sub.c +++ b/lib/timespec-sub.c @@ -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) { diff --git a/lib/xstrtol.c b/lib/xstrtol.c index 9695b42ee9..6a8e042e81 100644 --- a/lib/xstrtol.c +++ b/lib/xstrtol.c @@ -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; |