Summary: | gmtime does not return NULL if the input cannot be represented as struct tm | ||
---|---|---|---|
Product: | Base System | Reporter: | Uri Simchoni <urisimchoni> |
Component: | standards | Assignee: | freebsd-standards (Nobody) <standards> |
Status: | New --- | ||
Severity: | Affects Some People | CC: | kib |
Priority: | --- | ||
Version: | 12.0-RELEASE | ||
Hardware: | Any | ||
OS: | Any |
Description
Uri Simchoni
2019-06-13 18:30:49 UTC
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 Your issue should be handled by https://reviews.freebsd.org/D20631, but there is at least one test failure with the patch applied. It seems to break t_mktime:timegm_epoch. I am not sure where is a cause of the failure, in my patch, or is there one more bug in tzcode. |