Skip to content

Commit

Permalink
Fix UB in QProcess deprecation warning fixes
Browse files Browse the repository at this point in the history
The commits e1e0862 and 66e905b introduced undefined behavior. Fix
this by assigning the result of takeFirst to a temporary.

Change-Id: I9e29412cf632d4836b95d47e12d8c07ab0645fbb
Reviewed-by: Volker Hilsheimer <[email protected]>
  • Loading branch information
jobor committed Mar 6, 2020
1 parent 249a2e3 commit 2de3bfc
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
3 changes: 2 additions & 1 deletion src/corelib/io/qprocess.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2522,7 +2522,8 @@ int QProcess::execute(const QString &command)
QStringList args = splitCommand(command);
if (args.isEmpty())
return -2;
return execute(args.takeFirst(), args);
QString program = args.takeFirst();
return execute(program, args);
}

/*!
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,11 @@ static inline bool launch(const QString &launcher, const QUrl &url)
const bool ok = ::system(qPrintable(command + QLatin1String(" &")));
#else
QStringList args = QProcess::splitCommand(command);
const bool ok = !args.isEmpty() && QProcess::startDetached(args.takeFirst(), args);
bool ok = false;
if (!args.isEmpty()) {
QString program = args.takeFirst();
ok = QProcess::startDetached(program, args);
}
#endif
if (!ok)
qWarning("Launch failed (%s)", qPrintable(command));
Expand Down

0 comments on commit 2de3bfc

Please sign in to comment.