summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPaul Eggert <eggert@cs.ucla.edu>2023-05-17 15:07:38 -0700
committerPaul Eggert <eggert@cs.ucla.edu>2023-05-17 15:41:00 -0700
commitafbdae00ab59bbda971780fa04dd75dc7d1e7df7 (patch)
treea847a84dd9fe028c83db27eda0901cd45ed683ad
parent0bba1b8c3df8b7b53e08fd69dcc832d253e7a2d1 (diff)
downloademacs-afbdae00ab59bbda971780fa04dd75dc7d1e7df7.tar.gz
Update from Gnulib by running admin/merge-gnulib
-rw-r--r--lib/nstrftime.c44
-rw-r--r--lib/stat-time.h3
-rw-r--r--lib/timespec-add.c5
-rw-r--r--lib/timespec-sub.c5
4 files changed, 35 insertions, 22 deletions
diff --git a/lib/nstrftime.c b/lib/nstrftime.c
index 68bb560910d..2a1dd8d88d7 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>
@@ -226,15 +227,6 @@ extern char *tzname[];
# undef __mbsrtowcs_l
# define __mbsrtowcs_l(d, s, l, st, loc) __mbsrtowcs (d, s, l, st)
# endif
-# define widen(os, ws, l) \
- { \
- mbstate_t __st; \
- const char *__s = os; \
- memset (&__st, '\0', sizeof (__st)); \
- l = __mbsrtowcs_l (NULL, &__s, 0, &__st, loc); \
- ws = (wchar_t *) alloca ((l + 1) * sizeof (wchar_t)); \
- (void) __mbsrtowcs_l (ws, &__s, l, &__st, loc); \
- }
#endif
@@ -684,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;
}
@@ -1374,11 +1366,31 @@ __strftime_internal (STREAM_OR_CHAR_T *s, STRFTIME_ARG (size_t maxsize)
#ifdef COMPILE_WIDE
{
/* The zone string is always given in multibyte form. We have
- to transform it first. */
- wchar_t *wczone;
- size_t len;
- widen (zone, wczone, len);
- cpy (len, wczone);
+ to convert it to wide character. */
+ size_t w = pad == L_('-') || width < 0 ? 0 : width;
+ char const *z = zone;
+ mbstate_t st = {0};
+ size_t len = __mbsrtowcs_l (p, &z, maxsize - i, &st, loc);
+ if (len == (size_t) -1)
+ return 0;
+ size_t incr = len < w ? w : len;
+ if (incr >= maxsize - i)
+ {
+ errno = ERANGE;
+ return 0;
+ }
+ if (p)
+ {
+ if (len < w)
+ {
+ size_t delta = w - len;
+ wmemmove (p + delta, p, len);
+ wchar_t wc = pad == L_('0') || pad == L_('+') ? L'0' : L' ';
+ wmemset (p, wc, delta);
+ }
+ p += incr;
+ }
+ i += incr;
}
#else
cpy (strlen (zone), zone);
diff --git a/lib/stat-time.h b/lib/stat-time.h
index af084102dae..75eb27e549d 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 cb3017803b4..38c4dfc24c2 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 822c2831089..f8052400410 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)
{