From 6d786dec7c664a287d25fe834f3462a9a6cad297 Mon Sep 17 00:00:00 2001 From: Robin Getz Date: Fri, 7 Aug 2026 19:28:34 -0400 Subject: [PATCH 1/2] plutosdr: guard against null scan description Add a null check for the IIO scan context description before using it to construct a std::string or std::string_view. This also makes the non-null assumption explicit for static analysis and fixes Coverity CID 652283 (FORWARD_NULL). Signed-off-by: Robin Getz --- devices/plutosdr/deviceplutosdrscan.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/devices/plutosdr/deviceplutosdrscan.cpp b/devices/plutosdr/deviceplutosdrscan.cpp index e156d2de4..68e94cc3f 100644 --- a/devices/plutosdr/deviceplutosdrscan.cpp +++ b/devices/plutosdr/deviceplutosdrscan.cpp @@ -61,7 +61,7 @@ void DevicePlutoSDRScan::scan() const char *description = iio_context_info_get_description(info[i]); const char *uri = iio_context_info_get_uri(info[i]); - if (!DevicePlutoSDRBox::probeURI(std::string(uri))) { // continue if not accessible + if (!DevicePlutoSDRBox::probeURI(std::string(uri)) || !description) { continue; } @@ -69,7 +69,7 @@ void DevicePlutoSDRScan::scan() std::string fixedUri = replaceHostnameWithIP(uri, description); qDebug("PlutoSDRScan::scan: %d: %s [%s] [%s]", i, description, uri, fixedUri.c_str()); - const std::string_view descriptionView = description ? std::string_view{description} : std::string_view{}; + const std::string_view descriptionView = std::string_view{description}; const bool isPlutoDescription = (descriptionView.find("PlutoSDR") != std::string_view::npos) || (descriptionView.find("AD93") != std::string_view::npos); From 74c8c665182cfdbca3bdd7c0f4040470ea05371a Mon Sep 17 00:00:00 2001 From: Robin Getz Date: Fri, 7 Aug 2026 19:37:21 -0400 Subject: [PATCH 2/2] plutosdr: use move semantics in device scan Transfer ownership of the temporary fixed URI into DeviceScan and the newly created shared pointer into the scan list instead of copying them. Neither object is used after the transfer, so moving avoids unnecessary string and shared_ptr copies and makes the intended ownership transfer explicit. This fixes Coverity CIDs 652268 and 652358 (COPY_INSTEAD_OF_MOVE). Signed-off-by: Robin Getz --- devices/plutosdr/deviceplutosdrscan.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/devices/plutosdr/deviceplutosdrscan.cpp b/devices/plutosdr/deviceplutosdrscan.cpp index 68e94cc3f..8999435dc 100644 --- a/devices/plutosdr/deviceplutosdrscan.cpp +++ b/devices/plutosdr/deviceplutosdrscan.cpp @@ -24,6 +24,7 @@ #include #include #include +#include #include @@ -82,9 +83,9 @@ void DevicePlutoSDRScan::scan() DeviceScan({ std::string(description), std::string("TBD"), - fixedUri + std::move(fixedUri) })); - m_scans.push_back(dev_scan); + m_scans.push_back(std::move(dev_scan)); m_urilMap[m_scans.back()->m_uri] = m_scans.back(); std::regex desc_regex(".*serial=(.+)");