Search code examples
clinuxglibcmktime

mktime causes overflow in SLES 15 SP3


SLES 15 SP3 makes use of glibc 2.31 and our convert time code using mktime is failing with ulong overflow. Can anyone let us know if we are missing something here. Or do we have any other alternative system call that does the same?

main()
{
    time_t time_since_epoch = 0;
    struct tm gmTimetm; 
    gmTimetm.tm_year = 2022;
    gmTimetm.tm_mon = 02;
    gmTimetm.tm_mday = 24;
    gmTimetm.tm_hour = 11;
    gmTimetm.tm_min = 42;
    gmTimetm.tm_sec = 45;
    time_since_epoch = mktime(&gmTimetm);

    printf("%lu \n", time_since_epoch);
    return 0; 
}

OP: 18446744073709551615


Solution

  • The tm_isdst needs to be set to -1. With that the issue got resolved