mirror of
https://github.com/subsurface/subsurface.git
synced 2024-11-30 22:20:21 +00:00
Null check before writing to pointer
In the serial api for libdivecomputer is ok to send NULL as the int pointer actual, if you dont't care about how many bytes that where actually read or written. This makes sure we don't crash if the ble backend where ever used with such a backend. Signed-off-by: Anton Lundin <glance@acc.umu.se>
This commit is contained in:
parent
15962add7a
commit
7c6fa227ea
1 changed files with 4 additions and 2 deletions
|
@ -172,6 +172,7 @@ dc_status_t BLEObject::write(const void *data, size_t size, size_t *actual)
|
|||
|
||||
dc_status_t BLEObject::read(void *data, size_t size, size_t *actual)
|
||||
{
|
||||
if (actual)
|
||||
*actual = 0;
|
||||
if (receivedPackets.isEmpty()) {
|
||||
QList<QLowEnergyCharacteristic> list = preferredService()->characteristics();
|
||||
|
@ -198,6 +199,7 @@ dc_status_t BLEObject::read(void *data, size_t size, size_t *actual)
|
|||
return DC_STATUS_NOMEMORY;
|
||||
|
||||
memcpy((char *)data, packet.data(), packet.size());
|
||||
if (actual)
|
||||
*actual += packet.size();
|
||||
|
||||
return DC_STATUS_SUCCESS;
|
||||
|
|
Loading…
Reference in a new issue