aboutsummaryrefslogtreecommitdiffstats
path: root/epan/address.h
diff options
context:
space:
mode:
authorGuy Harris <guy@alum.mit.edu>2015-07-14 11:36:10 -0700
committerGuy Harris <guy@alum.mit.edu>2015-07-14 18:36:48 +0000
commit9230834fbe06f893bd581ab889b94122df5a9998 (patch)
tree04db9bd8e497a4919fac52634941e956faf3ed92 /epan/address.h
parentcdeae7e72b749cdd68207d6e97dafb67783e2de4 (diff)
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>
Diffstat (limited to 'epan/address.h')
-rw-r--r--epan/address.h6
1 files changed, 4 insertions, 2 deletions
diff --git a/epan/address.h b/epan/address.h
index 6e6faa3694..4ffcbe9e02 100644
--- a/epan/address.h
+++ b/epan/address.h
@@ -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)