summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorEdward Welbourne <edward.welbourne@qt.io>2020-08-10 17:50:44 +0200
committerEdward Welbourne <edward.welbourne@qt.io>2020-08-11 11:19:44 +0200
commit1f96709fdb78045bf5ed895c318e48f55ec29bf2 (patch)
tree719c6811dc6c3c19ac65eb429ac026e2036f7e70 /src
parent1b4a5af63f984a7eef40761e25f27cb5785c2351 (diff)
Tidy up use of local variables and add an assertion
Petty tidy-up, narrowing the scopes and asserting that localtime_r()'s return, when non-null, is the pointer we gave it. Change-Id: I6c0959524260028ca9b234f6d33eae78f27c1412 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Diffstat (limited to 'src')
-rw-r--r--src/corelib/time/qdatetime.cpp10
1 files changed, 4 insertions, 6 deletions
diff --git a/src/corelib/time/qdatetime.cpp b/src/corelib/time/qdatetime.cpp
index 7a3e49e076..5e1e620ec2 100644
--- a/src/corelib/time/qdatetime.cpp
+++ b/src/corelib/time/qdatetime.cpp
@@ -2491,19 +2491,17 @@ static bool qt_localtime(qint64 msecsSinceEpoch, QDate *localDate, QTime *localT
#if QT_CONFIG(thread) && defined(_POSIX_THREAD_SAFE_FUNCTIONS)
// Use the reentrant version of localtime() where available
// as is thread-safe and doesn't use a shared static data area
- tm *res = nullptr;
- res = localtime_r(&secsSinceEpoch, &local);
- if (res)
+ if (tm *res = localtime_r(&secsSinceEpoch, &local)) {
+ Q_ASSERT(res == &local);
valid = true;
+ }
#elif defined(Q_CC_MSVC)
if (!_localtime64_s(&local, &secsSinceEpoch))
valid = true;
#else
// Returns shared static data which may be overwritten at any time
// So copy the result asap
- tm *res = nullptr;
- res = localtime(&secsSinceEpoch);
- if (res) {
+ if (tm *res = localtime(&secsSinceEpoch)) {
local = *res;
valid = true;
}