[LTP] [PATCH] syscalls/time01:Avoid using TST_RET in time() test to support Y2038-safe time_t
jiaying.song.cn@windriver.com
jiaying.song.cn@windriver.com
Mon Oct 20 13:13:15 CEST 2025
From: Jiaying Song <jiaying.song.cn@windriver.com>
On 32-bit systems with Y2038 support, time_t is 64-bit while TST_RET
remains a long (usually 32-bit).Using TST_RET to store the return value
of time() causes overflow after 2038, leading to incorrect comparisons
and false test failures like:
TFAIL: time() returned value -2085977741, stored value 2208989555 are different
This patch replaces usage of TST_RET with a local variable of type
time_t (ret_time), ensuring correct behavior with large timestamps and
avoiding truncation.
Signed-off-by: Jiaying Song <jiaying.song.cn@windriver.com>
---
testcases/kernel/syscalls/time/time01.c | 17 ++++++++---------
1 file changed, 8 insertions(+), 9 deletions(-)
diff --git a/testcases/kernel/syscalls/time/time01.c b/testcases/kernel/syscalls/time/time01.c
index 9b176f892..7924f94b8 100644
--- a/testcases/kernel/syscalls/time/time01.c
+++ b/testcases/kernel/syscalls/time/time01.c
@@ -23,24 +23,23 @@ static time_t *targs[] = {
static void verify_time(unsigned int i)
{
time_t *tloc = targs[i];
+ time_t ret_time = time(tloc);
- TEST(time(tloc));
-
- if (TST_RET == -1) {
+ if (ret_time == -1) {
tst_res(TFAIL | TTERRNO, "time()");
return;
}
if (!tloc) {
- tst_res(TPASS, "time() returned value %ld", TST_RET);
- } else if (*tloc == TST_RET) {
+ tst_res(TPASS, "time() returned value %jd", (intmax_t) ret_time);
+ } else if (*tloc == ret_time) {
tst_res(TPASS,
- "time() returned value %ld, stored value %jd are same",
- TST_RET, (intmax_t) *tloc);
+ "time() returned value %jd, stored value %jd are same",
+ (intmax_t) ret_time, (intmax_t) *tloc);
} else {
tst_res(TFAIL,
- "time() returned value %ld, stored value %jd are different",
- TST_RET, (intmax_t) *tloc);
+ "time() returned value %jd, stored value %jd are different",
+ (intmax_t) ret_time, (intmax_t) *tloc);
}
}
--
2.34.1
More information about the ltp
mailing list