Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Windows: Reintroduce copy of argv.
Since argc/argv is modified by QCoreApplication-derived classes,
a copy of the original arguments is needed for comparison.

This fixes a crash in Qt Quick 2 tests (which use
the -qmljsdebugger=<port> argument) introduced
by dff18b8 .

Task-number: QTBUG-30330
Change-Id: Ic145ac923e0a7c504ab16602c8686268e4fd9700
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Reviewed-by: Simon Hausmann <simon.hausmann@theqtcompany.com>
  • Loading branch information
Friedemann Kleint authored and Simon Hausmann committed Feb 10, 2015
1 parent 0866680 commit 29daa76
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 7 deletions.
21 changes: 15 additions & 6 deletions src/corelib/kernel/qcoreapplication.cpp
Expand Up @@ -414,7 +414,8 @@ QCoreApplicationPrivate::QCoreApplicationPrivate(int &aargc, char **aargv, uint
argc(aargc)
, argv(aargv)
#if defined(Q_OS_WIN) && !defined(Q_OS_WINRT)
, modifiedArgv(false)
, origArgc(0)
, origArgv(Q_NULLPTR)
#endif
, application_type(QCoreApplicationPrivate::Tty)
#ifndef QT_NO_QOBJECT
Expand All @@ -432,7 +433,11 @@ QCoreApplicationPrivate::QCoreApplicationPrivate(int &aargc, char **aargv, uint
argv = (char **)&empty;
}
#if defined(Q_OS_WIN) && !defined(Q_OS_WINRT)
modifiedArgv = isArgvModified(argc, argv);
if (!isArgvModified(argc, argv)) {
origArgc = argc;
origArgv = new char *[argc];
std::copy(argv, argv + argc, origArgv);
}
#endif // Q_OS_WIN && !Q_OS_WINRT

#ifndef QT_NO_QOBJECT
Expand All @@ -457,6 +462,9 @@ QCoreApplicationPrivate::~QCoreApplicationPrivate()
{
#ifndef QT_NO_QOBJECT
cleanupThreadData();
#endif
#if defined(Q_OS_WIN) && !defined(Q_OS_WINRT)
delete [] origArgv;
#endif
QCoreApplicationPrivate::clearApplicationFilePath();
}
Expand Down Expand Up @@ -2194,11 +2202,12 @@ QStringList QCoreApplication::arguments()
}
#endif // Q_OS_WINCE

if (!self->d_func()->modifiedArgv) {
const QCoreApplicationPrivate *d = self->d_func();
if (d->origArgv) {
const QStringList allArguments = qWinCmdArgs(cmdline);
Q_ASSERT(allArguments.size() == __argc);
for (int i = 0; i < __argc; ++i) {
if (contains(ac, av, __argv[i]))
Q_ASSERT(allArguments.size() == d->origArgc);
for (int i = 0; i < d->origArgc; ++i) {
if (contains(ac, av, d->origArgv[i]))
list.append(allArguments.at(i));
}
return list;
Expand Down
3 changes: 2 additions & 1 deletion src/corelib/kernel/qcoreapplication_p.h
Expand Up @@ -116,7 +116,8 @@ class Q_CORE_EXPORT QCoreApplicationPrivate
int &argc;
char **argv;
#if defined(Q_OS_WIN) && !defined(Q_OS_WINRT)
bool modifiedArgv;
int origArgc;
char **origArgv; // store unmodified arguments for QCoreApplication::arguments()
#endif
void appendApplicationPathToLibraryPaths(void);

Expand Down

0 comments on commit 29daa76

Please sign in to comment.