From 1f96709fdb78045bf5ed895c318e48f55ec29bf2 Mon Sep 17 00:00:00 2001 From: Edward Welbourne Date: Mon, 10 Aug 2020 17:50:44 +0200 Subject: 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 --- src/corelib/time/qdatetime.cpp | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) (limited to 'src/corelib/time') 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; } -- cgit v1.2.3