From 92ba4b9cc7bbc2e1818191745d1976f9b915be9a Mon Sep 17 00:00:00 2001 From: Berthold Stoeger Date: Fri, 3 Nov 2017 17:44:09 +0100 Subject: [PATCH] Replace QMap::operator[] with QMap::value() QMap::operator[] creates a new default constructed entry in the map if no entry with the given key exists. While not problematic (since typically nullptrs are inserted) this is usually not what you want for read access. Signed-off-by: Berthold Stoeger --- core/btdiscovery.cpp | 2 +- desktop-widgets/configuredivecomputerdialog.cpp | 2 +- desktop-widgets/downloadfromdivecomputer.cpp | 2 +- mobile-widgets/qmlmapwidgethelper.cpp | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/core/btdiscovery.cpp b/core/btdiscovery.cpp index 731c4ca4f..ffa2a26f0 100644 --- a/core/btdiscovery.cpp +++ b/core/btdiscovery.cpp @@ -46,7 +46,7 @@ static dc_descriptor_t *getDeviceType(QString btName) } if (!vendor.isEmpty() && !product.isEmpty()) - return(descriptorLookup[vendor + product]); + return(descriptorLookup.value(vendor + product)); return(NULL); } diff --git a/desktop-widgets/configuredivecomputerdialog.cpp b/desktop-widgets/configuredivecomputerdialog.cpp index 0a601730f..296528fb0 100644 --- a/desktop-widgets/configuredivecomputerdialog.cpp +++ b/desktop-widgets/configuredivecomputerdialog.cpp @@ -908,7 +908,7 @@ void ConfigureDiveComputerDialog::getDeviceData() device_data.vendor = strdup(selected_vendor.toUtf8().data()); device_data.product = strdup(selected_product.toUtf8().data()); - device_data.descriptor = descriptorLookup[selected_vendor + selected_product]; + device_data.descriptor = descriptorLookup.value(selected_vendor + selected_product); device_data.deviceid = device_data.diveid = 0; auto dc = SettingsObjectWrapper::instance()->dive_computer_settings; diff --git a/desktop-widgets/downloadfromdivecomputer.cpp b/desktop-widgets/downloadfromdivecomputer.cpp index 3b551edef..59accbcd2 100644 --- a/desktop-widgets/downloadfromdivecomputer.cpp +++ b/desktop-widgets/downloadfromdivecomputer.cpp @@ -482,7 +482,7 @@ void DownloadFromDCWidget::updateDeviceEnabled() { // Set up the DC descriptor dc_descriptor_t *descriptor = NULL; - descriptor = descriptorLookup[ui.vendor->currentText() + ui.product->currentText()]; + descriptor = descriptorLookup.value(ui.vendor->currentText() + ui.product->currentText()); // call dc_descriptor_get_transport to see if the dc_transport_t is DC_TRANSPORT_SERIAL if (dc_descriptor_get_transport(descriptor) == DC_TRANSPORT_SERIAL) { diff --git a/mobile-widgets/qmlmapwidgethelper.cpp b/mobile-widgets/qmlmapwidgethelper.cpp index 1ad5503dc..ba197f63f 100644 --- a/mobile-widgets/qmlmapwidgethelper.cpp +++ b/mobile-widgets/qmlmapwidgethelper.cpp @@ -113,7 +113,7 @@ void MapWidgetHelper::reloadMapLocations() QString name(ds->name); // don't add dive locations with the same name, unless they are // at least MIN_DISTANCE_BETWEEN_DIVE_SITES_M apart - if (locationNameMap[name]) { + if (locationNameMap.contains(name)) { MapLocation *existingLocation = locationNameMap[name]; QGeoCoordinate coord = qvariant_cast(existingLocation->getRole(MapLocation::Roles::RoleCoordinate)); if (dsCoord.distanceTo(coord) < MIN_DISTANCE_BETWEEN_DIVE_SITES_M)