aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar Anton Lundin <glance@acc.umu.se>2017-07-12 21:23:02 +0200
committerGravatar Dirk Hohndel <dirk@hohndel.org>2017-08-01 13:39:35 -0700
commit7c6fa227eac300055c714be839274fc6f7e421cd (patch)
tree90e94cc2585c2971b71f21eb5927fba8056d7b7b
parent15962add7ad6fc42073b864135ac7783b46296f1 (diff)
downloadsubsurface-7c6fa227eac300055c714be839274fc6f7e421cd.tar.gz
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>
-rw-r--r--core/qt-ble.cpp6
1 files changed, 4 insertions, 2 deletions
diff --git a/core/qt-ble.cpp b/core/qt-ble.cpp
index 967827db1..cb471d119 100644
--- a/core/qt-ble.cpp
+++ b/core/qt-ble.cpp
@@ -172,7 +172,8 @@ 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)
{
- *actual = 0;
+ if (actual)
+ *actual = 0;
if (receivedPackets.isEmpty()) {
QList<QLowEnergyCharacteristic> list = preferredService()->characteristics();
if (list.isEmpty())
@@ -198,7 +199,8 @@ dc_status_t BLEObject::read(void *data, size_t size, size_t *actual)
return DC_STATUS_NOMEMORY;
memcpy((char *)data, packet.data(), packet.size());
- *actual += packet.size();
+ if (actual)
+ *actual += packet.size();
return DC_STATUS_SUCCESS;
}