From 0601f9f764c55390a2cdd71d91c3ea25c57f2a6d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Abecasis?= Date: Thu, 11 Feb 2010 17:31:53 +0100 Subject: Fix bug in QDirPrivate::setPath, affecting QDir::cd, cdUp and setPath The changes introduced in 9d713d7e73a88fe8328b55d2ab9af8c215dcb89d made QDirPrivate rely on the order of sub-expression evaluation. In some platform/compiler combinations, the instance of QDirPrivate::Data::path being changed would be the pre-detach one. With this change, that commit is partially reverted. Also, inlined the code in initFileEngine since this makes the actions therein explicit. Reviewed-by: Olivier Goffart --- src/corelib/io/qdir.cpp | 18 ++++++------------ 1 file changed, 6 insertions(+), 12 deletions(-) diff --git a/src/corelib/io/qdir.cpp b/src/corelib/io/qdir.cpp index f5d803e..7cfdddf 100644 --- a/src/corelib/io/qdir.cpp +++ b/src/corelib/io/qdir.cpp @@ -89,8 +89,6 @@ public: QDirPrivate(const QDir *copy = 0); ~QDirPrivate(); - QString initFileEngine(const QString &file); - void updateFileLists() const; void sortFileList(QDir::SortFlags, QFileInfoList &, QStringList *, QFileInfoList *) const; @@ -146,6 +144,7 @@ public: } *data; inline void setPath(const QString &p) { + detach(false); QString path = p; if ((path.endsWith(QLatin1Char('/')) || path.endsWith(QLatin1Char('\\'))) && path.length() > 1) { @@ -155,8 +154,12 @@ public: path.truncate(path.length() - 1); } + delete data->fileEngine; + data->fileEngine = QAbstractFileEngine::create(path); + // set the path to be the qt friendly version so then we can operate on it using just / - data->path = initFileEngine(path); + data->path = data->fileEngine->fileName(QAbstractFileEngine::DefaultName); + data->clear(); } inline void reset() { detach(); @@ -310,15 +313,6 @@ inline void QDirPrivate::updateFileLists() const } } -inline QString QDirPrivate::initFileEngine(const QString &path) -{ - detach(false); - data->clear(); - delete data->fileEngine; - data->fileEngine = QAbstractFileEngine::create(path); - return data->fileEngine->fileName(QAbstractFileEngine::DefaultName); -} - void QDirPrivate::detach(bool createFileEngine) { qAtomicDetach(data); -- cgit v0.12