Commit 27576416 by Edward Thomson

tests: only copy when `ptr` is non-NULL

Avoid passing a `NULL` ptr to `memcpy` -- that's UB (even if size is 0)
parent 8e5281c8
...@@ -73,13 +73,17 @@ static void *cl__realloc(void *ptr, size_t size, const char *file, int line) ...@@ -73,13 +73,17 @@ static void *cl__realloc(void *ptr, size_t size, const char *file, int line)
if (p) if (p)
memcpy(&copybytes, p - sizeof(size_t), sizeof(size_t)); memcpy(&copybytes, p - sizeof(size_t), sizeof(size_t));
if (copybytes > size) if (copybytes > size)
copybytes = size; copybytes = size;
if ((new = cl__malloc(size, file, line)) == NULL) if ((new = cl__malloc(size, file, line)) == NULL)
goto out; goto out;
if (p) {
memcpy(new, p, copybytes); memcpy(new, p, copybytes);
cl__free(p); cl__free(p);
}
out: out:
return new; return new;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment