From 7c0884f2a2b02ed91ee49f79ef2fff27c2567c39 Mon Sep 17 00:00:00 2001 From: Friedemann Kleint Date: Wed, 29 Aug 2018 09:07:43 +0200 Subject: 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 Reviewed-by: Thiago Macieira --- src/corelib/io/qprocess_win.cpp | 102 ++++++++++++++++++++-------------------- 1 file changed, 51 insertions(+), 51 deletions(-) (limited to 'src/corelib/io/qprocess_win.cpp') diff --git a/src/corelib/io/qprocess_win.cpp b/src/corelib/io/qprocess_win.cpp index 1f7a49379d..cb4b2f9f91 100644 --- a/src/corelib/io/qprocess_win.cpp +++ b/src/corelib/io/qprocess_win.cpp @@ -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; + + 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; + } - Channel *source; - Channel *sink; + CloseHandle(tmpHandle); + return true; + } - if (channel.type == Channel::PipeSource) { - // we are the source - source = &channel; - sink = &channel.process->stdinChannel; + Q_ASSERT(source == &stdoutChannel); + Q_ASSERT(sink->process == this && sink->type == Channel::PipeSink); - 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; + qt_create_pipe(source->pipe, /* in = */ false); // source is stdout + sink->pipe[0] = source->pipe[0]; + source->pipe[0] = INVALID_Q_PIPE; - CloseHandle(tmpHandle); - return true; + 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; } - 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; - + CloseHandle(tmpHandle); 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); + } + 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; + qt_create_pipe(sink->pipe, /* in = */ true); // sink is stdin + source->pipe[1] = sink->pipe[1]; + sink->pipe[1] = INVALID_Q_PIPE; - return true; - } + return true; } + } // switch (channel.type) + return false; } void QProcessPrivate::destroyPipe(Q_PIPE pipe[2]) -- cgit v1.2.3