diff options
| -rw-r--r-- | lib/nstrftime.c | 44 | ||||
| -rw-r--r-- | lib/stat-time.h | 3 | ||||
| -rw-r--r-- | lib/timespec-add.c | 5 | ||||
| -rw-r--r-- | lib/timespec-sub.c | 5 |
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[]; | |||
| 62 | #endif | 62 | #endif |
| 63 | 63 | ||
| 64 | #include <limits.h> | 64 | #include <limits.h> |
| 65 | #include <stdckdint.h> | ||
| 65 | #include <stddef.h> | 66 | #include <stddef.h> |
| 66 | #include <stdlib.h> | 67 | #include <stdlib.h> |
| 67 | #include <string.h> | 68 | #include <string.h> |
| @@ -226,15 +227,6 @@ extern char *tzname[]; | |||
| 226 | # undef __mbsrtowcs_l | 227 | # undef __mbsrtowcs_l |
| 227 | # define __mbsrtowcs_l(d, s, l, st, loc) __mbsrtowcs (d, s, l, st) | 228 | # define __mbsrtowcs_l(d, s, l, st, loc) __mbsrtowcs (d, s, l, st) |
| 228 | # endif | 229 | # endif |
| 229 | # define widen(os, ws, l) \ | ||
| 230 | { \ | ||
| 231 | mbstate_t __st; \ | ||
| 232 | const char *__s = os; \ | ||
| 233 | memset (&__st, '\0', sizeof (__st)); \ | ||
| 234 | l = __mbsrtowcs_l (NULL, &__s, 0, &__st, loc); \ | ||
| 235 | ws = (wchar_t *) alloca ((l + 1) * sizeof (wchar_t)); \ | ||
| 236 | (void) __mbsrtowcs_l (ws, &__s, l, &__st, loc); \ | ||
| 237 | } | ||
| 238 | #endif | 230 | #endif |
| 239 | 231 | ||
| 240 | 232 | ||
| @@ -684,8 +676,8 @@ __strftime_internal (STREAM_OR_CHAR_T *s, STRFTIME_ARG (size_t maxsize) | |||
| 684 | width = 0; | 676 | width = 0; |
| 685 | do | 677 | do |
| 686 | { | 678 | { |
| 687 | if (INT_MULTIPLY_WRAPV (width, 10, &width) | 679 | if (ckd_mul (&width, width, 10) |
| 688 | || INT_ADD_WRAPV (width, *f - L_('0'), &width)) | 680 | || ckd_add (&width, width, *f - L_('0'))) |
| 689 | width = INT_MAX; | 681 | width = INT_MAX; |
| 690 | ++f; | 682 | ++f; |
| 691 | } | 683 | } |
| @@ -1374,11 +1366,31 @@ __strftime_internal (STREAM_OR_CHAR_T *s, STRFTIME_ARG (size_t maxsize) | |||
| 1374 | #ifdef COMPILE_WIDE | 1366 | #ifdef COMPILE_WIDE |
| 1375 | { | 1367 | { |
| 1376 | /* The zone string is always given in multibyte form. We have | 1368 | /* The zone string is always given in multibyte form. We have |
| 1377 | to transform it first. */ | 1369 | to convert it to wide character. */ |
| 1378 | wchar_t *wczone; | 1370 | size_t w = pad == L_('-') || width < 0 ? 0 : width; |
| 1379 | size_t len; | 1371 | char const *z = zone; |
| 1380 | widen (zone, wczone, len); | 1372 | mbstate_t st = {0}; |
| 1381 | cpy (len, wczone); | 1373 | size_t len = __mbsrtowcs_l (p, &z, maxsize - i, &st, loc); |
| 1374 | if (len == (size_t) -1) | ||
| 1375 | return 0; | ||
| 1376 | size_t incr = len < w ? w : len; | ||
| 1377 | if (incr >= maxsize - i) | ||
| 1378 | { | ||
| 1379 | errno = ERANGE; | ||
| 1380 | return 0; | ||
| 1381 | } | ||
| 1382 | if (p) | ||
| 1383 | { | ||
| 1384 | if (len < w) | ||
| 1385 | { | ||
| 1386 | size_t delta = w - len; | ||
| 1387 | wmemmove (p + delta, p, len); | ||
| 1388 | wchar_t wc = pad == L_('0') || pad == L_('+') ? L'0' : L' '; | ||
| 1389 | wmemset (p, wc, delta); | ||
| 1390 | } | ||
| 1391 | p += incr; | ||
| 1392 | } | ||
| 1393 | i += incr; | ||
| 1382 | } | 1394 | } |
| 1383 | #else | 1395 | #else |
| 1384 | cpy (strlen (zone), zone); | 1396 | 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) | |||
| 221 | } | 221 | } |
| 222 | ts->tv_nsec = r; | 222 | ts->tv_nsec = r; |
| 223 | /* Overflow is possible, as Solaris 11 stat can yield | 223 | /* Overflow is possible, as Solaris 11 stat can yield |
| 224 | tv_sec == TYPE_MINIMUM (time_t) && tv_nsec == -1000000000. | 224 | tv_sec == TYPE_MINIMUM (time_t) && tv_nsec == -1000000000. */ |
| 225 | INT_ADD_WRAPV is OK, since time_t is signed on Solaris. */ | ||
| 226 | if (ckd_add (&ts->tv_sec, q, ts->tv_sec)) | 225 | if (ckd_add (&ts->tv_sec, q, ts->tv_sec)) |
| 227 | { | 226 | { |
| 228 | errno = EOVERFLOW; | 227 | 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 @@ | |||
| 23 | #include <config.h> | 23 | #include <config.h> |
| 24 | #include "timespec.h" | 24 | #include "timespec.h" |
| 25 | 25 | ||
| 26 | #include <stdckdint.h> | ||
| 26 | #include "intprops.h" | 27 | #include "intprops.h" |
| 27 | 28 | ||
| 28 | struct timespec | 29 | struct timespec |
| @@ -38,7 +39,7 @@ timespec_add (struct timespec a, struct timespec b) | |||
| 38 | { | 39 | { |
| 39 | rns = nsd; | 40 | rns = nsd; |
| 40 | time_t bs1; | 41 | time_t bs1; |
| 41 | if (!INT_ADD_WRAPV (bs, 1, &bs1)) | 42 | if (!ckd_add (&bs1, bs, 1)) |
| 42 | bs = bs1; | 43 | bs = bs1; |
| 43 | else if (rs < 0) | 44 | else if (rs < 0) |
| 44 | rs++; | 45 | rs++; |
| @@ -46,7 +47,7 @@ timespec_add (struct timespec a, struct timespec b) | |||
| 46 | goto high_overflow; | 47 | goto high_overflow; |
| 47 | } | 48 | } |
| 48 | 49 | ||
| 49 | if (INT_ADD_WRAPV (rs, bs, &rs)) | 50 | if (ckd_add (&rs, rs, bs)) |
| 50 | { | 51 | { |
| 51 | if (bs < 0) | 52 | if (bs < 0) |
| 52 | { | 53 | { |
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 @@ | |||
| 24 | #include <config.h> | 24 | #include <config.h> |
| 25 | #include "timespec.h" | 25 | #include "timespec.h" |
| 26 | 26 | ||
| 27 | #include <stdckdint.h> | ||
| 27 | #include "intprops.h" | 28 | #include "intprops.h" |
| 28 | 29 | ||
| 29 | struct timespec | 30 | struct timespec |
| @@ -38,7 +39,7 @@ timespec_sub (struct timespec a, struct timespec b) | |||
| 38 | { | 39 | { |
| 39 | rns = ns + TIMESPEC_HZ; | 40 | rns = ns + TIMESPEC_HZ; |
| 40 | time_t bs1; | 41 | time_t bs1; |
| 41 | if (!INT_ADD_WRAPV (bs, 1, &bs1)) | 42 | if (!ckd_add (&bs1, bs, 1)) |
| 42 | bs = bs1; | 43 | bs = bs1; |
| 43 | else if (- TYPE_SIGNED (time_t) < rs) | 44 | else if (- TYPE_SIGNED (time_t) < rs) |
| 44 | rs--; | 45 | rs--; |
| @@ -46,7 +47,7 @@ timespec_sub (struct timespec a, struct timespec b) | |||
| 46 | goto low_overflow; | 47 | goto low_overflow; |
| 47 | } | 48 | } |
| 48 | 49 | ||
| 49 | if (INT_SUBTRACT_WRAPV (rs, bs, &rs)) | 50 | if (ckd_sub (&rs, rs, bs)) |
| 50 | { | 51 | { |
| 51 | if (0 < bs) | 52 | if (0 < bs) |
| 52 | { | 53 | { |