[Bug 238547] gmtime does not return NULL if the input cannot be represented as struct tm

bugzilla-noreply at freebsd.org bugzilla-noreply at freebsd.org
Thu Jun 13 19:27:39 UTC 2019


https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=238547

--- Comment #1 from Uri Simchoni <urisimchoni at gmail.com> ---
Correction - if the input cannot be represented as struct tm, gmtime returns
whatever's in it's internal struct tm, and does not even set errno.

For example:

#include <time.h>
#include <stdlib.h>
#include <stdio.h>
#include <errno.h>
#include <string.h>

int main()
{
    time_t max_time = 0x7fffffffffffffffll;
    int e;
    errno = 0;
    tm = gmtime(&max_time);
    e = errno;
    printf("gmtime(0x7fffffffffffffffll) == %stm_year = %d errno = %d\n\n",
asctime(tm), tm->tm_year, e);
    max_time = 60000000000000000ll;
    errno = 0;
    tm = gmtime(&max_time);
    e = errno;
    printf("gmtime(60000000000000000ll) == %stm_year = %d errno = %d\n\n",
asctime(tm), tm->tm_year, e);
    max_time = 0x7fffffffffffffffll;
    errno = 0;
    tm = gmtime(&max_time);
    e = errno;
    printf("gmtime(0x7fffffffffffffffll) == %stm_year = %d errno = %d\n",
asctime(tm), tm->tm_year, e);
    return 0;
}

Yields the following output:
gmtime(0x7fffffffffffffffll) == Sun Jan  0 00:00:00 1900
tm_year = 0 errno = 0

gmtime(60000000000000000ll) == Sat May 29 10:40:00     1901326280
tm_year = 1901324380 errno = 0

gmtime(0x7fffffffffffffffll) == Sat May 29 10:40:00     1901326280
tm_year = 1901324380 errno = 0

-- 
You are receiving this mail because:
You are the assignee for the bug.


More information about the freebsd-standards mailing list