From 0b14af5624c178d6bffeb6799fd5798e2579e03b Mon Sep 17 00:00:00 2001 From: Aleix Pol Date: Mon, 26 Apr 2021 15:37:09 +0200 Subject: [PATCH] udev: Do not return a mysterious vector with just a null pointer When getting the vector, it requires us to check both if it's not empty but also that it's not null. I haven't seen it but we were not doing this check. Just return an empty vector when there's no devices instead. --- src/udev.cpp | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/src/udev.cpp b/src/udev.cpp index c35f0560de..c68a5724ac 100644 --- a/src/udev.cpp +++ b/src/udev.cpp @@ -98,11 +98,10 @@ void UdevEnumerate::scan() std::vector UdevEnumerate::find() { - std::vector vect; if (m_enumerate.isNull()) { - vect.push_back( UdevDevice::Ptr() ); - return vect; + return {}; } + std::vector vect; QString defaultSeat = QStringLiteral("seat0"); udev_list_entry *it = udev_enumerate_get_list_entry(m_enumerate.data()); while (it) { @@ -127,9 +126,7 @@ std::vector UdevEnumerate::find() std::vector Udev::listGPUs() { if (!m_udev) { - std::vector vect; - vect.push_back(UdevDevice::Ptr()); - return vect; + return {}; } #if defined(Q_OS_FREEBSD) std::vector r; @@ -159,9 +156,7 @@ std::vector Udev::listGPUs() std::vector Udev::listFramebuffers() { if (!m_udev) { - std::vector vect; - vect.push_back(UdevDevice::Ptr()); - return vect; + return {}; } UdevEnumerate enumerate(this); enumerate.addMatch(UdevEnumerate::Match::SubSystem, "graphics");