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 dff18b8e80 .

Task-number: QTBUG-30330
Change-Id: Ic145ac923e0a7c504ab16602c8686268e4fd9700
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Reviewed-by: Simon Hausmann <simon.hausmann@theqtcompany.com>
This commit is contained in:
Friedemann Kleint 2015-02-09 17:34:06 +01:00 committed by Simon Hausmann
parent 0866680bd9
commit 29daa7645b
2 changed files with 17 additions and 7 deletions

View File

@ -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
@ -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
@ -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();
}
@ -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;

View File

@ -116,7 +116,8 @@ public:
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);