Don't copy zero bytes of data.
memcpy(NULL, NULL, 0) isn't guaranteed by ISO C90 to work, so don't do it. Check whether the length is zero, and don't copy if it is. (If the count is non-zero and the pointer is null, that's an error, and we should fail there, so base the test on the length, not the pointer.) Change-Id: I0b3dc1541b52670d8fef459754c9494cfcc59e5d Reviewed-on: https://code.wireshark.org/review/9633 Reviewed-by: Guy Harris <guy@alum.mit.edu>
This commit is contained in:
parent
cdeae7e72b
commit
9230834fbe
|
@ -155,7 +155,8 @@ copy_address(address *to, const address *from) {
|
|||
to->type = from->type;
|
||||
to->len = from->len;
|
||||
to_data = (guint8 *)g_malloc(from->len);
|
||||
memcpy(to_data, from->data, from->len);
|
||||
if (from->len != 0)
|
||||
memcpy(to_data, from->data, from->len);
|
||||
to->data = to_data;
|
||||
}
|
||||
#define COPY_ADDRESS(to, from) copy_address((to), (from))
|
||||
|
@ -189,7 +190,8 @@ copy_address_shallow(address *to, const address *from) {
|
|||
void *WMEM_COPY_ADDRESS_data; \
|
||||
copy_address_shallow((to), (from)); \
|
||||
WMEM_COPY_ADDRESS_data = wmem_alloc(scope, (from)->len); \
|
||||
memcpy(WMEM_COPY_ADDRESS_data, (from)->data, (from)->len); \
|
||||
if ((from)->len != 0) \
|
||||
memcpy(WMEM_COPY_ADDRESS_data, (from)->data, (from)->len); \
|
||||
(to)->data = WMEM_COPY_ADDRESS_data; \
|
||||
} while (0)
|
||||
|
||||
|
|
Loading…
Reference in New Issue