[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 May 19 08:49:55 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 | 19 ++++++++++---------
1 file changed, 10 insertions(+), 9 deletions(-)
diff --git a/testcases/kernel/syscalls/time/time01.c b/testcases/kernel/syscalls/time/time01.c
index d8625c0..3da7f1c 100644
--- a/testcases/kernel/syscalls/time/time01.c
+++ b/testcases/kernel/syscalls/time/time01.c
@@ -24,24 +24,25 @@ time_t *targs[] = {
static void verify_time(unsigned int i)
{
time_t *tloc = targs[i];
+ time_t ret_time = time(tloc);
+
+ 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 %lld", 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 %lld, stored value %jd are same",
+ 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 %lld, stored value %jd are different",
+ ret_time, (intmax_t) *tloc);
}
static struct tst_test test = {
--
2.34.1
More information about the ltp
mailing list