[libc-commits] [libc] [libc] Complete hardening of time functions and remove Y2038 limit (PR #203298)

Pavel Labath via libc-commits libc-commits at lists.llvm.org
Thu Jun 11 23:33:18 PDT 2026


================
@@ -111,10 +112,14 @@ LIBC_INLINE IntFormatSection get_int_format(const FormatSection &to_conv,
     raw_num = time_reader.get_min();
     result.pad_to_len = 2;
     break;
-  case 's': // Seconds since the epoch
-    raw_num = time_reader.get_epoch();
+  case 's': { // Seconds since the epoch
+    auto epoch_or = time_reader.get_epoch();
+    if (!epoch_or)
+      return cpp::unexpected(epoch_or.error());
+    raw_num = epoch_or.value();
----------------
labath wrote:

This is better than the first version, but if I'm following this correctly, this error path is coming from time_utils::mktime_internal. This function used to fail due to Y2038 overflow, but that failure mode has been removed in https://github.com/llvm/llvm-project/pull/200426, and the function now always succeeds.

If he are happy with that state (we don't foresee adding new failure modes to that function), then we drop the `cpp::optional` from the function result, and revert the rest of these error handling paths.

https://github.com/llvm/llvm-project/pull/203298


More information about the libc-commits mailing list