[libc-commits] [libc] [libc] Fix gmtime test on systems with sizeof(time_t) == 4 (PR #65388)

Mikhail R. Gadelha via libc-commits libc-commits at lists.llvm.org
Tue Sep 5 10:31:42 PDT 2023


https://github.com/mikhailramalho created https://github.com/llvm/llvm-project/pull/65388:

This test creates a time_t variable and assigns 0xfffffffffe1d7b01 which overflows the maximum time_t value for 64-bit time_t, then checks if the syscall fails and errno was set.

In systems with sizeof(time_t) == 4, the value is narrowed down to 0xfe1d7b01 and doesn't overflow, causing the test to fail.

This patch then disables the test on systems with 32 bits long time_t.

>From 66502dbb2c25f4f9bf5190bd25107a88248d9db9 Mon Sep 17 00:00:00 2001
From: "Mikhail R. Gadelha" <mikhail at igalia.com>
Date: Fri, 1 Sep 2023 10:40:43 -0300
Subject: [PATCH] [libc] Fix gmtime test on systems with sizeof(time_t) == 4

This test creates a time_t variable and assigns 0xfffffffffe1d7b01 which
overflows the maximum time_t value for 64-bit time_t, then checks if the
syscall fails and errno was set.

In systems with sizeof(time_t) == 4, the value is narrowed down to 0xfe1d7b01
and doesn't overflow, causing the test to fail.

This patch then disables the test on systems with 32 bits long time_t.
---
 libc/test/src/time/gmtime_test.cpp | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/libc/test/src/time/gmtime_test.cpp b/libc/test/src/time/gmtime_test.cpp
index 07e3950bdcf24aa..e502f1d65e892ab 100644
--- a/libc/test/src/time/gmtime_test.cpp
+++ b/libc/test/src/time/gmtime_test.cpp
@@ -20,6 +20,8 @@ using __llvm_libc::testing::ErrnoSetterMatcher::Succeeds;
 using __llvm_libc::time_utils::TimeConstants;
 
 TEST(LlvmLibcGmTime, OutOfRange) {
+  if(sizeof(time_t) == 4)
+    return;
   time_t seconds =
       1 + INT_MAX * static_cast<int64_t>(
                         TimeConstants::NUMBER_OF_SECONDS_IN_LEAP_YEAR);



More information about the libc-commits mailing list