summaryrefslogtreecommitdiff
path: root/mysys
diff options
context:
space:
mode:
authorMarko Mäkelä <marko.makela@mariadb.com>2020-11-02 14:19:21 +0200
committerMarko Mäkelä <marko.makela@mariadb.com>2020-11-02 14:19:21 +0200
commit8036d0a3590dddf4d51ba02bc74ba3a5a96674f7 (patch)
tree13fc7d26725fc5fd58a058b5d8563afef0835ae3 /mysys
parentd2fab686670fcc6d23930298e4256734dfdbc413 (diff)
downloadmariadb-git-8036d0a3590dddf4d51ba02bc74ba3a5a96674f7.tar.gz
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.
Diffstat (limited to 'mysys')
-rw-r--r--mysys/array.c5
-rw-r--r--mysys/my_alloc.c2
2 files changed, 4 insertions, 3 deletions
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;
}