[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[xen staging] time: drop dead code from gmtime()



commit 4909438bc397b8d31d6b48a44498ca1ec242324b
Author:     Jan Beulich <jbeulich@xxxxxxxx>
AuthorDate: Mon May 11 13:19:31 2026 +0200
Commit:     Jan Beulich <jbeulich@xxxxxxxx>
CommitDate: Mon May 11 13:19:31 2026 +0200

    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 <jbeulich@xxxxxxxx>
    Acked-by: Andrew Cooper <andrew.cooper3@xxxxxxxxxx>
---
 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 */
--
generated by git-patchbot for /home/xen/git/xen.git#staging



 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.