From 4909438bc397b8d31d6b48a44498ca1ec242324b Mon Sep 17 00:00:00 2001 From: Jan Beulich Date: Mon, 11 May 2026 13:19:31 +0200 Subject: [PATCH] time: drop dead code from gmtime() "days", as calculated, can't be negative. Drop the respective loop and change its type. Similarly "rem" can't be negative and doesn't require more than 32 bits. Change its type, too. As a consequence, the tm_wday calculation also can't yield negative values, so the respective conditional can be dropped as well. Signed-off-by: Jan Beulich Acked-by: Andrew Cooper --- xen/common/time.c | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/xen/common/time.c b/xen/common/time.c index c873b5731b..04a65f00b3 100644 --- a/xen/common/time.c +++ b/xen/common/time.c @@ -45,7 +45,8 @@ static DEFINE_SPINLOCK(wc_lock); struct tm gmtime(unsigned long t) { struct tm tbuf; - long days, rem; + unsigned long days; + unsigned int rem; int y; const unsigned short int *ip; @@ -70,18 +71,11 @@ struct tm gmtime(unsigned long t) tbuf.tm_sec = rem % 60; /* January 1, 1970 was a Thursday. */ tbuf.tm_wday = (4 + days) % 7; - if ( tbuf.tm_wday < 0 ) - tbuf.tm_wday += 7; while ( days >= (rem = __isleap(y) ? 366 : 365) ) { ++y; days -= rem; } - while ( days < 0 ) - { - --y; - days += __isleap(y) ? 366 : 365; - } tbuf.tm_year = y - 1900; tbuf.tm_yday = days; /* SAF-14-safe use boolean as an array index */