* 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 | 10 ++++++++++ lib/nstrftime.c | 5 +++-- lib/stat-time.h | 3 +-- lib/timespec-add.c | 5 +++-- lib/timespec-sub.c | 5 +++-- lib/xstrtol.c | 3 ++- modules/nstrftime | 1 + modules/timespec-add | 1 + modules/timespec-sub | 1 + modules/xstrtol | 1 + 10 files changed, 26 insertions(+), 9 deletions(-)
diff --git a/ChangeLog b/ChangeLog index 36b3c65b81..fc4e43a881 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,15 @@ 2023-05-17 Paul Eggert <egg...@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 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; diff --git a/modules/nstrftime b/modules/nstrftime index a24af8dcb3..fdaf7913d3 100644 --- a/modules/nstrftime +++ b/modules/nstrftime @@ -15,6 +15,7 @@ extensions intprops libc-config stdbool +stdckdint time_rz configure.ac: diff --git a/modules/timespec-add b/modules/timespec-add index 68050bf856..45daf6e26b 100644 --- a/modules/timespec-add +++ b/modules/timespec-add @@ -7,6 +7,7 @@ lib/timespec-add.c Depends-on: c99 intprops +stdckdint timespec configure.ac: diff --git a/modules/timespec-sub b/modules/timespec-sub index f442ceafbb..d7316a5c9c 100644 --- a/modules/timespec-sub +++ b/modules/timespec-sub @@ -7,6 +7,7 @@ lib/timespec-sub.c Depends-on: c99 intprops +stdckdint timespec configure.ac: diff --git a/modules/xstrtol b/modules/xstrtol index 137cc1f5ab..c9712dee0c 100644 --- a/modules/xstrtol +++ b/modules/xstrtol @@ -10,6 +10,7 @@ m4/xstrtol.m4 Depends-on: assure intprops +stdckdint stdint configure.ac: -- 2.39.2