Windows code: Fix clang-tidy warnings about else after jumps

Replace by switch() where appropriate, remove else and unindent code
or simplify the return value.

Change-Id: Ie988b9068a9579ae5a899b3765e43aad480b564e
Reviewed-by: Edward Welbourne <edward.welbourne@qt.io>
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
This commit is contained in:
Friedemann Kleint 2018-08-29 09:07:43 +02:00
parent 30756f4626
commit 7c0884f2a2
12 changed files with 143 additions and 146 deletions

View File

@ -106,8 +106,7 @@ bool QFileSystemIterator::advance(QFileSystemEntry &fileEntry, QFileSystemMetaDa
QLatin1String("\\\\") + parts.at(2), &uncShares)) {
if (uncShares.isEmpty())
return false; // No shares found in the server
else
uncFallback = true;
uncFallback = true;
}
}
}

View File

@ -667,7 +667,8 @@ void QWindowsFileSystemWatcherEngineThread::run()
if (m != '@')
DEBUG() << "QWindowsFileSystemWatcherEngine: unknown message sent to thread: " << char(m);
break;
} else if (r > WAIT_OBJECT_0 && r < WAIT_OBJECT_0 + uint(handlesCopy.count())) {
}
if (r > WAIT_OBJECT_0 && r < WAIT_OBJECT_0 + uint(handlesCopy.count())) {
int at = r - WAIT_OBJECT_0;
Q_ASSERT(at < handlesCopy.count());
HANDLE handle = handlesCopy.at(at);

View File

@ -766,10 +766,9 @@ QString QFSFileEngine::fileName(FileName file) const
int slash = ret.lastIndexOf(QLatin1Char('/'));
if (slash < 0)
return ret;
else if (ret.at(0) != QLatin1Char('/') && slash == 2)
if (ret.at(0) != QLatin1Char('/') && slash == 2)
return ret.left(3); // include the slash
else
return ret.left(slash > 0 ? slash : 1);
return ret.left(slash > 0 ? slash : 1);
}
return ret;
} else if (file == CanonicalName || file == CanonicalPathName) {

View File

@ -202,7 +202,8 @@ bool QProcessPrivate::openChannel(Channel &channel)
&stderrChannel.pipe[1], 0, TRUE, DUPLICATE_SAME_ACCESS);
}
if (channel.type == Channel::Normal) {
switch (channel.type) {
case Channel::Normal:
// we're piping this channel to our own process
if (&channel == &stdinChannel) {
if (inputChannelMode != QProcess::ForwardedInputChannel) {
@ -242,9 +243,8 @@ bool QProcessPrivate::openChannel(Channel &channel)
channel.reader->startAsyncRead();
}
}
return true;
} else if (channel.type == Channel::Redirect) {
case Channel::Redirect: {
// we're redirecting the channel to/from a file
SECURITY_ATTRIBUTES secAtt = { sizeof(SECURITY_ATTRIBUTES), NULL, TRUE };
@ -289,65 +289,65 @@ bool QProcessPrivate::openChannel(Channel &channel)
}
cleanup();
return false;
} else {
}
case Channel::PipeSource: {
Q_ASSERT_X(channel.process, "QProcess::start", "Internal error");
// we are the source
Channel *source = &channel;
Channel *sink = &channel.process->stdinChannel;
Channel *source;
Channel *sink;
if (channel.type == Channel::PipeSource) {
// we are the source
source = &channel;
sink = &channel.process->stdinChannel;
if (source->pipe[1] != INVALID_Q_PIPE) {
// already constructed by the sink
// make it inheritable
HANDLE tmpHandle = source->pipe[1];
if (!DuplicateHandle(GetCurrentProcess(), tmpHandle,
GetCurrentProcess(), &source->pipe[1],
0, TRUE, DUPLICATE_SAME_ACCESS))
return false;
CloseHandle(tmpHandle);
return true;
if (source->pipe[1] != INVALID_Q_PIPE) {
// already constructed by the sink
// make it inheritable
HANDLE tmpHandle = source->pipe[1];
if (!DuplicateHandle(GetCurrentProcess(), tmpHandle,
GetCurrentProcess(), &source->pipe[1],
0, TRUE, DUPLICATE_SAME_ACCESS)) {
return false;
}
Q_ASSERT(source == &stdoutChannel);
Q_ASSERT(sink->process == this && sink->type == Channel::PipeSink);
qt_create_pipe(source->pipe, /* in = */ false); // source is stdout
sink->pipe[0] = source->pipe[0];
source->pipe[0] = INVALID_Q_PIPE;
return true;
} else {
// we are the sink;
source = &channel.process->stdoutChannel;
sink = &channel;
if (sink->pipe[0] != INVALID_Q_PIPE) {
// already constructed by the source
// make it inheritable
HANDLE tmpHandle = sink->pipe[0];
if (!DuplicateHandle(GetCurrentProcess(), tmpHandle,
GetCurrentProcess(), &sink->pipe[0],
0, TRUE, DUPLICATE_SAME_ACCESS))
return false;
CloseHandle(tmpHandle);
return true;
}
Q_ASSERT(sink == &stdinChannel);
Q_ASSERT(source->process == this && source->type == Channel::PipeSource);
qt_create_pipe(sink->pipe, /* in = */ true); // sink is stdin
source->pipe[1] = sink->pipe[1];
sink->pipe[1] = INVALID_Q_PIPE;
CloseHandle(tmpHandle);
return true;
}
Q_ASSERT(source == &stdoutChannel);
Q_ASSERT(sink->process == this && sink->type == Channel::PipeSink);
qt_create_pipe(source->pipe, /* in = */ false); // source is stdout
sink->pipe[0] = source->pipe[0];
source->pipe[0] = INVALID_Q_PIPE;
return true;
}
case Channel::PipeSink: { // we are the sink;
Q_ASSERT_X(channel.process, "QProcess::start", "Internal error");
Channel *source = &channel.process->stdoutChannel;
Channel *sink = &channel;
if (sink->pipe[0] != INVALID_Q_PIPE) {
// already constructed by the source
// make it inheritable
HANDLE tmpHandle = sink->pipe[0];
if (!DuplicateHandle(GetCurrentProcess(), tmpHandle,
GetCurrentProcess(), &sink->pipe[0],
0, TRUE, DUPLICATE_SAME_ACCESS)) {
return false;
}
CloseHandle(tmpHandle);
return true;
}
Q_ASSERT(sink == &stdinChannel);
Q_ASSERT(source->process == this && source->type == Channel::PipeSource);
qt_create_pipe(sink->pipe, /* in = */ true); // sink is stdin
source->pipe[1] = sink->pipe[1];
sink->pipe[1] = INVALID_Q_PIPE;
return true;
}
} // switch (channel.type)
return false;
}
void QProcessPrivate::destroyPipe(Q_PIPE pipe[2])

View File

@ -837,26 +837,32 @@ bool QWinSettingsPrivate::isWritable() const
QSettingsPrivate *QSettingsPrivate::create(QSettings::Format format, QSettings::Scope scope,
const QString &organization, const QString &application)
{
if (format == QSettings::NativeFormat)
switch (format) {
case QSettings::NativeFormat:
return new QWinSettingsPrivate(scope, organization, application);
else if (format == QSettings::Registry32Format)
case QSettings::Registry32Format:
return new QWinSettingsPrivate(scope, organization, application, KEY_WOW64_32KEY);
else if (format == QSettings::Registry64Format)
case QSettings::Registry64Format:
return new QWinSettingsPrivate(scope, organization, application, KEY_WOW64_64KEY);
else
return new QConfFileSettingsPrivate(format, scope, organization, application);
default:
break;
}
return new QConfFileSettingsPrivate(format, scope, organization, application);
}
QSettingsPrivate *QSettingsPrivate::create(const QString &fileName, QSettings::Format format)
{
if (format == QSettings::NativeFormat)
switch (format) {
case QSettings::NativeFormat:
return new QWinSettingsPrivate(fileName);
else if (format == QSettings::Registry32Format)
case QSettings::Registry32Format:
return new QWinSettingsPrivate(fileName, KEY_WOW64_32KEY);
else if (format == QSettings::Registry64Format)
case QSettings::Registry64Format:
return new QWinSettingsPrivate(fileName, KEY_WOW64_64KEY);
else
return new QConfFileSettingsPrivate(fileName, format);
default:
break;
}
return new QConfFileSettingsPrivate(fileName, format);
}
QT_END_NAMESPACE

View File

@ -270,13 +270,11 @@ void QWindowsPipeReader::readFileCompleted(DWORD errorCode, DWORD numberOfBytesT
DWORD QWindowsPipeReader::checkPipeState()
{
DWORD bytes;
if (PeekNamedPipe(handle, NULL, 0, NULL, &bytes, NULL)) {
if (PeekNamedPipe(handle, nullptr, 0, nullptr, &bytes, nullptr))
return bytes;
} else {
if (!pipeBroken) {
pipeBroken = true;
emit pipeClosed();
}
if (!pipeBroken) {
pipeBroken = true;
emit pipeClosed();
}
return 0;
}

View File

@ -72,10 +72,9 @@ static inline qint64 ticksToNanoseconds(qint64 ticks)
qint64 seconds = ticks / counterFrequency;
qint64 nanoSeconds = (ticks - seconds * counterFrequency) * 1000000000 / counterFrequency;
return seconds * 1000000000 + nanoSeconds;
} else {
// GetTickCount(64) return milliseconds
return ticks * 1000000;
}
// GetTickCount(64) returns milliseconds
return ticks * 1000000;
}
static inline qint64 nanosecondsToTicks(qint64 nsec)
@ -115,10 +114,7 @@ QElapsedTimer::ClockType QElapsedTimer::clockType() Q_DECL_NOTHROW
{
resolveCounterFrequency();
if (counterFrequency > 0)
return PerformanceCounter;
else
return TickCounter;
return counterFrequency > 0 ? PerformanceCounter : TickCounter;
}
bool QElapsedTimer::isMonotonic() Q_DECL_NOTHROW

View File

@ -141,9 +141,9 @@ LRESULT QT_WIN_CALLBACK qt_internal_proc(HWND hwnd, UINT message, WPARAM wp, LPA
if (message == WM_TIMER)
KillTimer(hwnd, wp);
return 0;
} else if (dispatcher->filterNativeEvent(QByteArrayLiteral("windows_dispatcher_MSG"), &msg, &result)) {
return result;
}
if (dispatcher->filterNativeEvent(QByteArrayLiteral("windows_dispatcher_MSG"), &msg, &result))
return result;
#ifdef GWLP_USERDATA
auto q = reinterpret_cast<QEventDispatcherWin32 *>(GetWindowLongPtr(hwnd, GWLP_USERDATA));
@ -154,7 +154,8 @@ LRESULT QT_WIN_CALLBACK qt_internal_proc(HWND hwnd, UINT message, WPARAM wp, LPA
if (q != 0)
d = q->d_func();
if (message == WM_QT_SOCKETNOTIFIER) {
switch (message) {
case WM_QT_SOCKETNOTIFIER: {
// socket notifier message
int type = -1;
switch (WSAGETSELECTEVENT(lp)) {
@ -202,7 +203,8 @@ LRESULT QT_WIN_CALLBACK qt_internal_proc(HWND hwnd, UINT message, WPARAM wp, LPA
}
}
return 0;
} else if (message == WM_QT_ACTIVATENOTIFIERS) {
}
case WM_QT_ACTIVATENOTIFIERS: {
Q_ASSERT(d != 0);
// Postpone activation if we have unhandled socket notifier messages
@ -226,22 +228,25 @@ LRESULT QT_WIN_CALLBACK qt_internal_proc(HWND hwnd, UINT message, WPARAM wp, LPA
}
d->activateNotifiersPosted = false;
return 0;
} else if (message == WM_QT_SENDPOSTEDEVENTS
// we also use a Windows timer to send posted events when the message queue is full
|| (message == WM_TIMER
&& d->sendPostedEventsWindowsTimerId != 0
&& wp == (uint)d->sendPostedEventsWindowsTimerId)) {
}
case WM_TIMER:
if (d->sendPostedEventsWindowsTimerId == 0
|| wp != uint(d->sendPostedEventsWindowsTimerId)) {
Q_ASSERT(d != 0);
d->sendTimerEvent(wp);
return 0;
}
// we also use a Windows timer to send posted events when the message queue is full
Q_FALLTHROUGH();
case WM_QT_SENDPOSTEDEVENTS: {
const int localSerialNumber = d->serialNumber.load();
if (localSerialNumber != d->lastSerialNumber) {
d->lastSerialNumber = localSerialNumber;
q->sendPostedEvents();
}
return 0;
} else if (message == WM_TIMER) {
Q_ASSERT(d != 0);
d->sendTimerEvent(wp);
return 0;
}
} // switch (message)
return DefWindowProc(hwnd, message, wp, lp);
}
@ -683,7 +688,8 @@ void QEventDispatcherWin32::registerSocketNotifier(QSocketNotifier *notifier)
if (sockfd < 0) {
qWarning("QSocketNotifier: Internal error");
return;
} else if (notifier->thread() != thread() || thread() != QThread::currentThread()) {
}
if (notifier->thread() != thread() || thread() != QThread::currentThread()) {
qWarning("QSocketNotifier: socket notifiers cannot be enabled from another thread");
return;
}
@ -743,7 +749,8 @@ void QEventDispatcherWin32::unregisterSocketNotifier(QSocketNotifier *notifier)
if (sockfd < 0) {
qWarning("QSocketNotifier: Internal error");
return;
} else if (notifier->thread() != thread() || thread() != QThread::currentThread()) {
}
if (notifier->thread() != thread() || thread() != QThread::currentThread()) {
qWarning("QSocketNotifier: socket notifiers cannot be disabled from another thread");
return;
}
@ -789,7 +796,8 @@ void QEventDispatcherWin32::registerTimer(int timerId, int interval, Qt::TimerTy
if (timerId < 1 || interval < 0 || !object) {
qWarning("QEventDispatcherWin32::registerTimer: invalid arguments");
return;
} else if (object->thread() != thread() || thread() != QThread::currentThread()) {
}
if (object->thread() != thread() || thread() != QThread::currentThread()) {
qWarning("QEventDispatcherWin32::registerTimer: timers cannot be started from another thread");
return;
}
@ -987,14 +995,8 @@ int QEventDispatcherWin32::remainingTime(int timerId)
WinTimerInfo *t;
for (int i=0; i<d->timerVec.size(); i++) {
t = d->timerVec.at(i);
if (t && t->timerId == timerId) { // timer found
if (currentTime < t->timeout) {
// time to wait
return t->timeout - currentTime;
} else {
return 0;
}
}
if (t && t->timerId == timerId) // timer found, return time to wait
return t->timeout > currentTime ? t->timeout - currentTime : 0;
}
#ifndef QT_NO_DEBUG
@ -1054,7 +1056,8 @@ void QEventDispatcherWin32::closingDown()
bool QEventDispatcherWin32::event(QEvent *e)
{
Q_D(QEventDispatcherWin32);
if (e->type() == QEvent::ZeroTimerEvent) {
switch (e->type()) {
case QEvent::ZeroTimerEvent: {
QZeroTimerEvent *zte = static_cast<QZeroTimerEvent*>(e);
WinTimerInfo *t = d->timerDict.value(zte->timerId());
if (t) {
@ -1076,9 +1079,12 @@ bool QEventDispatcherWin32::event(QEvent *e)
}
}
return true;
} else if (e->type() == QEvent::Timer) {
QTimerEvent *te = static_cast<QTimerEvent*>(e);
d->sendTimerEvent(te->timerId());
}
case QEvent::Timer:
d->sendTimerEvent(static_cast<const QTimerEvent*>(e)->timerId());
break;
default:
break;
}
return QAbstractEventDispatcher::event(e);
}

View File

@ -143,10 +143,7 @@ bool QSharedMemoryPrivate::create(int size)
setErrorString(function);
// hand is valid when it already exists unlike unix so explicitly check
if (error == QSharedMemory::AlreadyExists || !hand)
return false;
return true;
return error != QSharedMemory::AlreadyExists && hand;
}
bool QSharedMemoryPrivate::attach(QSharedMemory::AccessMode mode)

View File

@ -260,31 +260,27 @@ DWORD WINAPI qt_adopted_thread_watcher_function(LPVOID)
}
const int handleIndex = offset + ret - WAIT_OBJECT_0;
if (handleIndex == 0){
// New handle to watch was added.
if (handleIndex == 0) // New handle to watch was added.
continue;
} else {
// printf("(qt) - qt_adopted_thread_watcher_function... called\n");
const int qthreadIndex = handleIndex - 1;
const int qthreadIndex = handleIndex - 1;
qt_adopted_thread_watcher_mutex.lock();
QThreadData *data = QThreadData::get2(qt_adopted_qthreads.at(qthreadIndex));
qt_adopted_thread_watcher_mutex.unlock();
if (data->isAdopted) {
QThread *thread = data->thread;
Q_ASSERT(thread);
QThreadPrivate *thread_p = static_cast<QThreadPrivate *>(QObjectPrivate::get(thread));
Q_UNUSED(thread_p)
Q_ASSERT(!thread_p->finished);
thread_p->finish(thread);
}
data->deref();
QMutexLocker lock(&qt_adopted_thread_watcher_mutex);
CloseHandle(qt_adopted_thread_handles.at(handleIndex));
qt_adopted_thread_handles.remove(handleIndex);
qt_adopted_qthreads.remove(qthreadIndex);
qt_adopted_thread_watcher_mutex.lock();
QThreadData *data = QThreadData::get2(qt_adopted_qthreads.at(qthreadIndex));
qt_adopted_thread_watcher_mutex.unlock();
if (data->isAdopted) {
QThread *thread = data->thread;
Q_ASSERT(thread);
auto thread_p = static_cast<QThreadPrivate *>(QObjectPrivate::get(thread));
Q_UNUSED(thread_p)
Q_ASSERT(!thread_p->finished);
QThreadPrivate::finish(thread);
}
data->deref();
QMutexLocker lock(&qt_adopted_thread_watcher_mutex);
CloseHandle(qt_adopted_thread_handles.at(handleIndex));
qt_adopted_thread_handles.remove(handleIndex);
qt_adopted_qthreads.remove(qthreadIndex);
}
QThreadData *threadData = reinterpret_cast<QThreadData *>(TlsGetValue(qt_current_thread_data_tls_index));

View File

@ -365,7 +365,7 @@ QVariant QSystemLocalePrivate::dayName(int day, QLocale::FormatType type)
if (type == QLocale::LongFormat)
return getLocaleInfo(long_day_map[day]);
else if (type == QLocale::NarrowFormat)
if (type == QLocale::NarrowFormat)
return getLocaleInfo(narrow_day_map[day]);
return getLocaleInfo(short_day_map[day]);
}
@ -386,7 +386,7 @@ QVariant QSystemLocalePrivate::monthName(int month, QLocale::FormatType type)
month -= 1;
if (month < 0 || month > 11)
return QString();
return QString();
LCTYPE lctype = (type == QLocale::ShortFormat || type == QLocale::NarrowFormat)
? short_month_map[month] : long_month_map[month];
@ -988,7 +988,7 @@ LCID qt_inIsoNametoLCID(const char *name)
// handle norwegian manually, the list above will fail
if (!strncmp(name, "nb", 2))
return 0x0414;
else if (!strncmp(name, "nn", 2))
if (!strncmp(name, "nn", 2))
return 0x0814;
char n[64];
@ -1099,8 +1099,7 @@ static QByteArray getWinLocaleName(LPWSTR id)
id = qstrtoll(result.data(), 0, 0, &ok);
if ( !ok || id == 0 || id < INT_MIN || id > INT_MAX )
return result;
else
return winLangCodeToIsoName( (int)id );
return winLangCodeToIsoName(int(id));
}
}

View File

@ -688,10 +688,10 @@ QString QWinTimeZonePrivate::displayName(QTimeZone::TimeType timeType,
if (nameType == QTimeZone::OffsetName) {
const QWinTransitionRule &rule =
m_tranRules.at(ruleIndexForYear(m_tranRules, QDate::currentDate().year()));
int offset = rule.standardTimeBias;
if (timeType == QTimeZone::DaylightTime)
return isoOffsetFormat((rule.standardTimeBias + rule.daylightTimeBias) * -60);
else
return isoOffsetFormat((rule.standardTimeBias) * -60);
offset += rule.daylightTimeBias;
return isoOffsetFormat(offset * -60);
}
switch (timeType) {