diff --git a/src/corelib/io/qstorageinfo_linux.cpp b/src/corelib/io/qstorageinfo_linux.cpp index 5b034bf4c2..502cb322fb 100644 --- a/src/corelib/io/qstorageinfo_linux.cpp +++ b/src/corelib/io/qstorageinfo_linux.cpp @@ -139,17 +139,21 @@ void QStorageInfoPrivate::initRootPath() const QString oldRootPath = rootPath; rootPath.clear(); - for (auto &info : infos) { + const MountInfo *bestInfo = nullptr; + for (const MountInfo &info : infos) { // we try to find most suitable entry qsizetype mpSize = info.mountPoint.size(); if (isParentOf(info.mountPoint, oldRootPath) && maxLength < mpSize) { + bestInfo = &info; maxLength = mpSize; - rootPath = info.mountPoint; - device = info.device; - fileSystemType = info.fsType; - subvolume = info.fsRoot; } } + if (bestInfo) { + rootPath = bestInfo->mountPoint; + device = bestInfo->device; + fileSystemType = bestInfo->fsType; + subvolume = bestInfo->fsRoot; + } } QList QStorageInfoPrivate::mountedVolumes()