Fixed evaluation of application file path

Empty arguments list could lead to crash, due to access of first element.
Besides, empty application file path will be cached now universally.

Change-Id: Ibe1a668da364d87d8431567dfc999cb394686081
Reviewed-by: Sérgio Martins <sergio.martins.qnx@kdab.com>
Reviewed-by: Fabian Bumberger <fbumberger@rim.com>
Reviewed-by: Thomas McGuire <thomas.mcguire@kdab.com>
This commit is contained in:
Bernd Weimer 2013-05-27 10:23:07 +02:00 committed by The Qt Project
parent 4f2c96eaa8
commit fd956af257

View File

@ -1952,7 +1952,6 @@ QString QCoreApplication::applicationFilePath()
char buff[maximum_path+1];
if (_cmdname(buff)) {
d->cachedApplicationFilePath = QDir::cleanPath(QString::fromLocal8Bit(buff));
return d->cachedApplicationFilePath;
} else {
qWarning("QCoreApplication::applicationFilePath: _cmdname() failed");
// _cmdname() won't fail, but just in case, fallback to the old method
@ -1961,11 +1960,11 @@ QString QCoreApplication::applicationFilePath()
if (!executables.empty()) {
//We assume that there is only one executable in the folder
d->cachedApplicationFilePath = dir.absoluteFilePath(executables.first());
return d->cachedApplicationFilePath;
} else {
return QString();
d->cachedApplicationFilePath = QString();
}
}
return d->cachedApplicationFilePath;
#elif defined(Q_OS_MAC)
QString qAppFileName_str = qAppFileName();
if(!qAppFileName_str.isEmpty()) {
@ -1984,7 +1983,7 @@ QString QCoreApplication::applicationFilePath()
return d->cachedApplicationFilePath;
}
# endif
if (!arguments().isEmpty()) {
QString argv0 = QFile::decodeName(arguments().at(0).toLocal8Bit());
QString absPath;
@ -2012,6 +2011,10 @@ QString QCoreApplication::applicationFilePath()
QFileInfo fi(absPath);
d->cachedApplicationFilePath = fi.exists() ? fi.canonicalFilePath() : QString();
} else {
d->cachedApplicationFilePath = QString();
}
return d->cachedApplicationFilePath;
#endif
}