diff options
author | Marc Mutz <marc.mutz@qt.io> | 2024-03-25 17:16:53 +0100 |
---|---|---|
committer | Marc Mutz <marc.mutz@qt.io> | 2024-03-25 23:29:33 +0100 |
commit | ae8031b5e72032f9e2884c18cd72639acfd0d1a4 (patch) | |
tree | a6254cd276092be703f1447e7117d38c4f17e144 /src/corelib/io/qstorageinfo_linux.cpp | |
parent | 25652c281960aa5647bc137dcee54b7e712e4897 (diff) |
QStorageInfo: fix use-after-move
Coverity complained about a use of the moved-from (in the first line
of the loop) `info` object in subsequent lines.
This specific instance is harmless, because the field being accesssed
is a scalar and the move SMFs are the default ones, so the field isn't
actually changed when the struct is moved from.
Still, to silence Coverity and to guide other attentive readers of the
code, take a copy of the field before moving from the struct, and use
the copy's value after the move.
Amends ddc39eb3a46d699c23d39f0e914978199eb98cc6.
Amends 3e330a79ec8d273630660eefae42995018421c0c.
Pick-to: 6.7
Coverity-Id: 444199
Change-Id: I26ea8669f27124fb2567b16d803d47ab439f1e41
Reviewed-by: Ahmad Samir <a.samirh78@gmail.com>
Diffstat (limited to 'src/corelib/io/qstorageinfo_linux.cpp')
-rw-r--r-- | src/corelib/io/qstorageinfo_linux.cpp | 5 |
1 files changed, 3 insertions, 2 deletions
diff --git a/src/corelib/io/qstorageinfo_linux.cpp b/src/corelib/io/qstorageinfo_linux.cpp index 7d9828fa3b..8707f6f7e0 100644 --- a/src/corelib/io/qstorageinfo_linux.cpp +++ b/src/corelib/io/qstorageinfo_linux.cpp @@ -268,13 +268,14 @@ QList<QStorageInfo> QStorageInfoPrivate::mountedVolumes() QList<QStorageInfo> volumes; for (MountInfo &info : infos) { + const auto infoStDev = info.stDev; QStorageInfoPrivate d(std::move(info)); d.retrieveVolumeInfo(); if (d.bytesTotal <= 0 && d.rootPath != u'/') continue; - if (info.stDev != deviceIdForPath(d.rootPath)) + if (infoStDev != deviceIdForPath(d.rootPath)) continue; // probably something mounted over this mountpoint - d.name = labelForDevice(d, info.stDev); + d.name = labelForDevice(d, infoStDev); volumes.emplace_back(QStorageInfo(*new QStorageInfoPrivate(std::move(d)))); } return volumes; |