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.
This commit is contained in:
Aleix Pol 2021-04-26 15:37:09 +02:00
parent 0e433cb83a
commit 0b14af5624

View file

@ -98,11 +98,10 @@ void UdevEnumerate::scan()
std::vector<UdevDevice::Ptr> UdevEnumerate::find() std::vector<UdevDevice::Ptr> UdevEnumerate::find()
{ {
std::vector<UdevDevice::Ptr> vect;
if (m_enumerate.isNull()) { if (m_enumerate.isNull()) {
vect.push_back( UdevDevice::Ptr() ); return {};
return vect;
} }
std::vector<UdevDevice::Ptr> vect;
QString defaultSeat = QStringLiteral("seat0"); QString defaultSeat = QStringLiteral("seat0");
udev_list_entry *it = udev_enumerate_get_list_entry(m_enumerate.data()); udev_list_entry *it = udev_enumerate_get_list_entry(m_enumerate.data());
while (it) { while (it) {
@ -127,9 +126,7 @@ std::vector<UdevDevice::Ptr> UdevEnumerate::find()
std::vector<UdevDevice::Ptr> Udev::listGPUs() std::vector<UdevDevice::Ptr> Udev::listGPUs()
{ {
if (!m_udev) { if (!m_udev) {
std::vector<UdevDevice::Ptr> vect; return {};
vect.push_back(UdevDevice::Ptr());
return vect;
} }
#if defined(Q_OS_FREEBSD) #if defined(Q_OS_FREEBSD)
std::vector<UdevDevice::Ptr> r; std::vector<UdevDevice::Ptr> r;
@ -159,9 +156,7 @@ std::vector<UdevDevice::Ptr> Udev::listGPUs()
std::vector<UdevDevice::Ptr> Udev::listFramebuffers() std::vector<UdevDevice::Ptr> Udev::listFramebuffers()
{ {
if (!m_udev) { if (!m_udev) {
std::vector<UdevDevice::Ptr> vect; return {};
vect.push_back(UdevDevice::Ptr());
return vect;
} }
UdevEnumerate enumerate(this); UdevEnumerate enumerate(this);
enumerate.addMatch(UdevEnumerate::Match::SubSystem, "graphics"); enumerate.addMatch(UdevEnumerate::Match::SubSystem, "graphics");