1
0
mirror of https://git.savannah.gnu.org/git/emacs.git synced 2024-11-23 07:19:15 +00:00

Update from Gnulib by running admin/merge-gnulib

This commit is contained in:
Paul Eggert 2023-05-17 15:07:38 -07:00
parent 0bba1b8c3d
commit afbdae00ab
4 changed files with 35 additions and 22 deletions

View File

@ -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);

View 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;

View 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)
{

View 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)
{