diff --git a/src/corelib/time/qlocaltime.cpp b/src/corelib/time/qlocaltime.cpp index 4f7496834a..60df487af6 100644 --- a/src/corelib/time/qlocaltime.cpp +++ b/src/corelib/time/qlocaltime.cpp @@ -222,27 +222,30 @@ int getCurrentStandardUtcOffset() #else qTzSet(); const time_t curr = time(nullptr); - /* Set t to the UTC representation of curr; the time whose local standard - time representation coincides with that differs from curr by local time's - standard offset. Note that gmtime() leaves the tm_isdst flag set to 0, - so mktime() will, even if local time is currently using DST, return the - time since epoch at which local standard time would have the same - representation as UTC's representation of curr. The fact that mktime() - also flips tm_isdst and updates the time fields to the DST-equivalent - time needn't concern us here; all that matters is that it returns the - time after epoch at which standard time's representation would have - matched UTC's, had it been in effect. - */ + if (curr != -1) { + /* Set t to the UTC representation of curr; the time whose local + standard time representation coincides with that differs from curr by + local time's standard offset. Note that gmtime() leaves the tm_isdst + flag set to 0, so mktime() will, even if local time is currently + using DST, return the time since epoch at which local standard time + would have the same representation as UTC's representation of + curr. The fact that mktime() also flips tm_isdst and updates the time + fields to the DST-equivalent time needn't concern us here; all that + matters is that it returns the time after epoch at which standard + time's representation would have matched UTC's, had it been in + effect. + */ # if defined(_POSIX_THREAD_SAFE_FUNCTIONS) - struct tm t; - if (gmtime_r(&curr, &t)) - return curr - qMkTime(&t); + struct tm t; + if (gmtime_r(&curr, &t)) + return curr - qMkTime(&t); # else - if (struct tm *tp = gmtime(&curr)) { - struct tm t = *tp; // Copy it quick, hopefully before it can get stomped - return curr - qMkTime(&t); - } + if (struct tm *tp = gmtime(&curr)) { + struct tm t = *tp; // Copy it quick, hopefully before it can get stomped + return curr - qMkTime(&t); + } # endif + } // else, presumably: errno == EOVERFLOW #endif // Platform choice qDebug("Unable to determine current standard time offset from UTC"); // We can't tell, presume UTC.