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.
This commit is contained in:
Jef Driesen 2019-02-21 21:54:58 +01:00 committed by Jef Driesen
parent 3287e3bd5d
commit d876542d39

View File

@ -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) {