From b3144ac26b1e32ec5d30c85367762dd622f30399 Mon Sep 17 00:00:00 2001 From: Jef Driesen Date: Thu, 28 Jun 2018 08:44:19 +0200 Subject: [PATCH] Don't pass a NULL pointer to memcpy The memcpy and related functions expects a valid pointer, even if the size is zero. Most libc implementations will handle a NULL pointer just fine, but that's not guaranteed. Simply skip the call when there is nothing to copy. --- src/tecdiving_divecomputereu.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/tecdiving_divecomputereu.c b/src/tecdiving_divecomputereu.c index 66d2117..cf88b30 100644 --- a/src/tecdiving_divecomputereu.c +++ b/src/tecdiving_divecomputereu.c @@ -117,7 +117,9 @@ tecdiving_divecomputereu_send (tecdiving_divecomputereu_device_t *device, unsign (size >> 24) & 0xFF, cmd, }; - memcpy(packet + 7, data, size); + if (size) { + memcpy(packet + 7, data, size); + } crc = checksum_crc (packet + 1, size + 6, 0); packet[size + 7] = (crc >> 8) & 0xFF; packet[size + 8] = (crc ) & 0xFF;