QLocalTime: getCurrentStandardUtcOffset: fix narrowing warnings
UTC offset in seconds can't be bigger than 24 hours, so it should fit in an int. Explicitly cast to int and add asserts. Change-Id: I45460a0489a134e4ad03bdab112f067d5913709a Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
This commit is contained in:
parent
5bffb47d6e
commit
f948835e62
@ -202,12 +202,19 @@ int getCurrentStandardUtcOffset()
|
||||
*/
|
||||
# if defined(_POSIX_THREAD_SAFE_FUNCTIONS)
|
||||
struct tm t;
|
||||
if (gmtime_r(&curr, &t))
|
||||
return curr - qMkTime(&t);
|
||||
if (gmtime_r(&curr, &t)) {
|
||||
time_t mkt = qMkTime(&t);
|
||||
int offset = int(curr - mkt);
|
||||
Q_ASSERT(std::abs(offset) <= SECS_PER_DAY);
|
||||
return offset;
|
||||
}
|
||||
# else
|
||||
if (struct tm *tp = gmtime(&curr)) {
|
||||
struct tm t = *tp; // Copy it quick, hopefully before it can get stomped
|
||||
return curr - qMkTime(&t);
|
||||
time_t mkt = qMkTime(&t);
|
||||
int offset = int(curr - mkt);
|
||||
Q_ASSERT(std::abs(offset) <= SECS_PER_DAY);
|
||||
return offset;
|
||||
}
|
||||
# endif
|
||||
} // else, presumably: errno == EOVERFLOW
|
||||
|
Loading…
x
Reference in New Issue
Block a user