diff options
Diffstat (limited to 'gl/mktime.c')
-rw-r--r-- | gl/mktime.c | 13 |
1 files changed, 7 insertions, 6 deletions
diff --git a/gl/mktime.c b/gl/mktime.c index 94a4320..c704f41 100644 --- a/gl/mktime.c +++ b/gl/mktime.c | |||
@@ -1,5 +1,5 @@ | |||
1 | /* Convert a 'struct tm' to a time_t value. | 1 | /* Convert a 'struct tm' to a time_t value. |
2 | Copyright (C) 1993-2023 Free Software Foundation, Inc. | 2 | Copyright (C) 1993-2024 Free Software Foundation, Inc. |
3 | This file is part of the GNU C Library. | 3 | This file is part of the GNU C Library. |
4 | Contributed by Paul Eggert <eggert@twinsun.com>. | 4 | Contributed by Paul Eggert <eggert@twinsun.com>. |
5 | 5 | ||
@@ -46,6 +46,7 @@ | |||
46 | #include <errno.h> | 46 | #include <errno.h> |
47 | #include <limits.h> | 47 | #include <limits.h> |
48 | #include <stdbool.h> | 48 | #include <stdbool.h> |
49 | #include <stdckdint.h> | ||
49 | #include <stdlib.h> | 50 | #include <stdlib.h> |
50 | #include <string.h> | 51 | #include <string.h> |
51 | 52 | ||
@@ -379,7 +380,7 @@ __mktime_internal (struct tm *tp, | |||
379 | /* Invert CONVERT by probing. First assume the same offset as last | 380 | /* Invert CONVERT by probing. First assume the same offset as last |
380 | time. */ | 381 | time. */ |
381 | 382 | ||
382 | INT_SUBTRACT_WRAPV (0, off, &negative_offset_guess); | 383 | ckd_sub (&negative_offset_guess, 0, off); |
383 | long_int t0 = ydhms_diff (year, yday, hour, min, sec, | 384 | long_int t0 = ydhms_diff (year, yday, hour, min, sec, |
384 | EPOCH_YEAR - TM_YEAR_BASE, 0, 0, 0, | 385 | EPOCH_YEAR - TM_YEAR_BASE, 0, 0, 0, |
385 | negative_offset_guess); | 386 | negative_offset_guess); |
@@ -465,7 +466,7 @@ __mktime_internal (struct tm *tp, | |||
465 | for (direction = -1; direction <= 1; direction += 2) | 466 | for (direction = -1; direction <= 1; direction += 2) |
466 | { | 467 | { |
467 | long_int ot; | 468 | long_int ot; |
468 | if (! INT_ADD_WRAPV (t, delta * direction, &ot)) | 469 | if (! ckd_add (&ot, t, delta * direction)) |
469 | { | 470 | { |
470 | struct tm otm; | 471 | struct tm otm; |
471 | if (! ranged_convert (convert, &ot, &otm)) | 472 | if (! ranged_convert (convert, &ot, &otm)) |
@@ -503,8 +504,8 @@ __mktime_internal (struct tm *tp, | |||
503 | /* Set *OFFSET to the low-order bits of T - T0 - NEGATIVE_OFFSET_GUESS. | 504 | /* Set *OFFSET to the low-order bits of T - T0 - NEGATIVE_OFFSET_GUESS. |
504 | This is just a heuristic to speed up the next mktime call, and | 505 | This is just a heuristic to speed up the next mktime call, and |
505 | correctness is unaffected if integer overflow occurs here. */ | 506 | correctness is unaffected if integer overflow occurs here. */ |
506 | INT_SUBTRACT_WRAPV (t, t0, offset); | 507 | ckd_sub (offset, t, t0); |
507 | INT_SUBTRACT_WRAPV (*offset, negative_offset_guess, offset); | 508 | ckd_sub (offset, *offset, negative_offset_guess); |
508 | 509 | ||
509 | if (LEAP_SECONDS_POSSIBLE && sec_requested != tm.tm_sec) | 510 | if (LEAP_SECONDS_POSSIBLE && sec_requested != tm.tm_sec) |
510 | { | 511 | { |
@@ -513,7 +514,7 @@ __mktime_internal (struct tm *tp, | |||
513 | long_int sec_adjustment = sec == 0 && tm.tm_sec == 60; | 514 | long_int sec_adjustment = sec == 0 && tm.tm_sec == 60; |
514 | sec_adjustment -= sec; | 515 | sec_adjustment -= sec; |
515 | sec_adjustment += sec_requested; | 516 | sec_adjustment += sec_requested; |
516 | if (INT_ADD_WRAPV (t, sec_adjustment, &t) | 517 | if (ckd_add (&t, t, sec_adjustment) |
517 | || ! (mktime_min <= t && t <= mktime_max)) | 518 | || ! (mktime_min <= t && t <= mktime_max)) |
518 | { | 519 | { |
519 | __set_errno (EOVERFLOW); | 520 | __set_errno (EOVERFLOW); |