[libc-commits] [libc] [libc] Fix overflow check for 32 bit long time_t (PR #65394)
via libc-commits
libc-commits at lists.llvm.org
Tue Sep 5 11:19:35 PDT 2023
================
@@ -48,20 +48,20 @@ int64_t update_from_seconds(int64_t total_seconds, struct tm *tm) {
static const char daysInMonth[] = {31 /* Mar */, 30, 31, 30, 31, 31,
30, 31, 30, 31, 31, 29};
- if (sizeof(time_t) == 4) {
- if (total_seconds < 0x80000000)
- return time_utils::out_of_range();
- if (total_seconds > 0x7FFFFFFF)
- return time_utils::out_of_range();
- } else {
- if (total_seconds <
- INT_MIN * static_cast<int64_t>(
- TimeConstants::NUMBER_OF_SECONDS_IN_LEAP_YEAR) ||
- total_seconds >
- INT_MAX * static_cast<int64_t>(
- TimeConstants::NUMBER_OF_SECONDS_IN_LEAP_YEAR))
- return time_utils::out_of_range();
- }
+ constexpr time_t time_min =
+ (sizeof(time_t) == 4)
+ ? static_cast<time_t>(0x80000000)
----------------
lntue wrote:
Why don't we use `INT_MIN / INT_MAX` or `LONG_MIN / LONG_MAX` for these constants?
https://github.com/llvm/llvm-project/pull/65394
More information about the libc-commits
mailing list