From 04149623c18b83e8eac9fe6f84d669c3dbd4d8fc Mon Sep 17 00:00:00 2001 From: Berthold Stoeger Date: Wed, 4 Nov 2020 23:04:17 +0100 Subject: core: don't construct std::string from null in device.cpp MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Recently the QStrings were replaced by std::strings in device.cpp so that they can be accessed from C-code. However, libstd being modelled after C, constructing a std::string from a NULL pointer leads to a crash. Fix one case where this was overlooked. Moreover, replace a null-pointer check by empty_string(), to treat NULL and "" equally. Reported-by: Salvador Cuñat Signed-off-by: Berthold Stoeger --- core/device.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'core') diff --git a/core/device.cpp b/core/device.cpp index 8c78fe43c..c251144a2 100644 --- a/core/device.cpp +++ b/core/device.cpp @@ -37,7 +37,7 @@ bool device::operator<(const device &a) const extern "C" const struct device *get_device_for_dc(const struct device_table *table, const struct divecomputer *dc) { const std::vector &dcs = table->devices; - device dev { dc->model, dc->deviceid, {}, {}, {} }; + device dev { dc->model ?: "", dc->deviceid, {}, {}, {} }; auto it = std::lower_bound(dcs.begin(), dcs.end(), dev); return it != dcs.end() && same_device(*it, dev) ? &*it : NULL; } @@ -60,7 +60,7 @@ extern "C" void set_dc_deviceid(struct divecomputer *dc, unsigned int deviceid, dc->deviceid = deviceid; // Serial and firmware can only be deduced if we know the model - if (!dc->model) + if (empty_string(dc->model)) return; const device *node = get_device_for_dc(device_table, dc); -- cgit v1.2.3-70-g09d2