[all-commits] [llvm/llvm-project] 81d827: [libc] Fix overflow check for 32-bit mktime. (#101...

Simon Tatham via All-commits all-commits at lists.llvm.org
Tue Aug 6 20:51:50 PDT 2024


  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: 81d8273978ace8b9a2b8cfd811b94e95f9560ac5
      https://github.com/llvm/llvm-project/commit/81d8273978ace8b9a2b8cfd811b94e95f9560ac5
  Author: Simon Tatham <simon.tatham at arm.com>
  Date:   2024-08-06 (Tue, 06 Aug 2024)

  Changed paths:
    M libc/src/time/mktime.cpp
    M libc/test/src/time/mktime_test.cpp

  Log Message:
  -----------
  [libc] Fix overflow check for 32-bit mktime. (#101993)

The 32-bit time_t rolls over to a value with its high bit set at
2038-01-19 03:14:07. The overflow check for this in mktime() was
checking each individual component of the time: reject if year>2038, or
if month>1, or if day>19, etc. As a result it would reject valid times
before the overflow point, because a low-order component was out of
range even though a higher-order one makes the time as a whole safe. The
earliest failing value is 2145916808 == 2038-01-01 00:00:08, in which
only the seconds field 'overflows'.

Fixed so that if any component is _less_ than its threshold value, we
don't check the lower-order components.



To unsubscribe from these emails, change your notification settings at https://github.com/llvm/llvm-project/settings/notifications


More information about the All-commits mailing list