From ae8031b5e72032f9e2884c18cd72639acfd0d1a4 Mon Sep 17 00:00:00 2001 From: Marc Mutz Date: Mon, 25 Mar 2024 17:16:53 +0100 Subject: 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 --- src/corelib/io/qstorageinfo_linux.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'src/corelib/io/qstorageinfo_linux.cpp') 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 QStorageInfoPrivate::mountedVolumes() QList 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; -- cgit v1.2.3