In less than 25 years – as of this month – a large range of devices will encounter a long-standing, well-understood bug unless updated. Larry Seltzer, editorial director of BYTE, Dark Reading and Network Computing, recently noted the approach of the Year 2038 bug, also known as Y2038 or Y2K38, which will arrive on January 19, 2038, at 03:14:08 UTC.
The Y2038 bug stems from the use of a 32-bit signed integer to store time values as a number of seconds since 00:00:00 UTC on Thursday, 1 January 1970. This practice began on early UNIX systems that used the C library data structure time_t. If the original standard had used an unsigned integer, the life of time value data types would be extended to 2106. Using 64-bit storage to define time_t would extend the wrap-around date forward 290 billion years, contributor Ruchit S. noted on the Code Project website.
While it is anticipated that most programs will use 64-bit storage for time values by 2038, many older systems are not equipped to handle dates in this way. Apple and others have advocated for the NSDate class for dates, which uses January 1, 2001 as a reference point. However, Apple’s current iOS is one victim of the Y2038 bug, Seltzer noted. He found that any attempt to set the iPhone to a date beyond January 19, 2038, resets the date to January 1 of that year. The same problem holds true in Android devices.
Fixing the problem in many devices and applications would be very challenging, as redefining the time_t structure as 64-bit would break the binary compatibility of many programs, Ruchit S. noted. Given the complications of modifying software, developers should ensure they are building plans for this issue into their programs, particularly if their software includes functions such as projections past a 25-year date window. Using tools such as static analysis, coders can scan for functions in their programs that might be impacted and catch loopholes such as this one before they turn into real issues.
Software news brought to you by Klocwork Inc., dedicated to helping software developers create better code with every keystroke.