Although the size of time_t is 8, on a 64-bit platform there are restrictions defined in the implementation, hardcoded at run time, which cannot be exceeded. When these limits are exceeded, gmtime will return NULL with errno set to indicate the nature of the error. Your code cannot check for NULL returns from gmtime, so asctime does not work when it tries to dereference a null pointer. This is a danger that you risk when using idiomatic C and do not check return values ββfrom functions that may fail.
Microsoft C gmtime on Windows 10 returns NULL with errno set to EINVAL when passing 32535291600. Although you might think that the theoretical maximum limit should be LLONG_MAX. Microsoft explicitly sets a limit on _MAX__TIME64_T + _MAX_LOCAL_TIME.
From ctime.h in Microsoft Visual Studio 2010 CRT sources:
#define _MAX__TIME64_T 0x793406fffi64
The Apple gmtime function returns NULL and errno set to EOVERFLOW when it passed 67768036191676800. The Apple implementation shows undefined behavior for all times when asctime () returns a string with more than 4 digits per year, because for standard C the function returns no more 26 characters.
QwazyWabbit
source share