From d876542d39a27ed39d38f7d80d52e6460c541843 Mon Sep 17 00:00:00 2001 From: Jef Driesen Date: Thu, 21 Feb 2019 21:54:58 +0100 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/divesystem_idive.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/divesystem_idive.c b/src/divesystem_idive.c index 2303186..180ccb6 100644 --- a/src/divesystem_idive.c +++ b/src/divesystem_idive.c @@ -319,7 +319,9 @@ divesystem_idive_packet (divesystem_idive_device_t *device, const unsigned char goto error; } - memcpy(answer, packet + 1, length - 2); + if (length > 2) { + memcpy (answer, packet + 1, length - 2); + } error: if (errorcode) {