From 8036d0a3590dddf4d51ba02bc74ba3a5a96674f7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marko=20M=C3=A4kel=C3=A4?= Date: Mon, 2 Nov 2020 14:19:21 +0200 Subject: MDEV-22387: Do not violate __attribute__((nonnull)) This follows up commit commit 94a520ddbe39ae97de1135d98699cf2674e6b77e and commit 7c5519c12d46ead947d341cbdcbb6fbbe4d4fe1b. After these changes, the default test suites on a cmake -DWITH_UBSAN=ON build no longer fail due to passing null pointers as parameters that are declared to never be null, but plenty of other runtime errors remain. --- mysys/array.c | 5 +++-- mysys/my_alloc.c | 2 +- 2 files changed, 4 insertions(+), 3 deletions(-) (limited to 'mysys') diff --git a/mysys/array.c b/mysys/array.c index 07abc460de7..e8b253a9e99 100644 --- a/mysys/array.c +++ b/mysys/array.c @@ -138,8 +138,9 @@ void *alloc_dynamic(DYNAMIC_ARRAY *array) array->size_of_element, MYF(array->malloc_flags | MY_WME)))) DBUG_RETURN(0); - memcpy(new_ptr, array->buffer, - array->elements * array->size_of_element); + if (array->elements) + memcpy(new_ptr, array->buffer, + array->elements * array->size_of_element); array->malloc_flags&= ~MY_INIT_BUFFER_USED; } else if (!(new_ptr=(char*) diff --git a/mysys/my_alloc.c b/mysys/my_alloc.c index 5bfcb455b8a..d67b8be9bb8 100644 --- a/mysys/my_alloc.c +++ b/mysys/my_alloc.c @@ -461,7 +461,7 @@ char *strmake_root(MEM_ROOT *root, const char *str, size_t len) void *memdup_root(MEM_ROOT *root, const void *str, size_t len) { char *pos; - if ((pos=alloc_root(root,len))) + if ((pos=alloc_root(root,len)) && len) memcpy(pos,str,len); return pos; } -- cgit v1.2.1