summaryrefslogtreecommitdiffstats
path: root/src/corelib/time/qlocaltime.cpp
diff options
context:
space:
mode:
authorAhmad Samir <a.samirh78@gmail.com>2023-03-11 03:24:09 +0200
committerAhmad Samir <a.samirh78@gmail.com>2023-03-13 23:26:28 +0200
commitf948835e6238d5185168374a05f8da2fc5c4482d (patch)
tree1941ee0c7ea77801ff9c7f7ad32608123ddf336f /src/corelib/time/qlocaltime.cpp
parent5bffb47d6e45260953bc679e1e9582322064b753 (diff)
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>
Diffstat (limited to 'src/corelib/time/qlocaltime.cpp')
-rw-r--r--src/corelib/time/qlocaltime.cpp13
1 files changed, 10 insertions, 3 deletions
diff --git a/src/corelib/time/qlocaltime.cpp b/src/corelib/time/qlocaltime.cpp
index 3b9a236ccf1..d8c0a3f823d 100644
--- a/src/corelib/time/qlocaltime.cpp
+++ b/src/corelib/time/qlocaltime.cpp
@@ -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