mirror of
https://github.com/subsurface/subsurface.git
synced 2025-01-19 06:15:26 +00:00
core: don't construct std::string from null in device.cpp
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 <salvador.cunat@gmail.com> Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
This commit is contained in:
parent
be3190db8a
commit
04149623c1
1 changed files with 2 additions and 2 deletions
|
@ -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<device> &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);
|
||||
|
|
Loading…
Add table
Reference in a new issue