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.

Coverity-Id: 444199
Change-Id: I26ea8669f27124fb2567b16d803d47ab439f1e41
Reviewed-by: Ahmad Samir <a.samirh78@gmail.com>
(cherry picked from commit ae8031b5e72032f9e2884c18cd72639acfd0d1a4)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
This commit is contained in:
Marc Mutz 2024-03-25 17:16:53 +01:00 committed by Qt Cherry-pick Bot
parent 251bddc661
commit de8d62589d

View File

@ -273,13 +273,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;