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)
if (p)
memcpy(&copybytes, p - sizeof(size_t), sizeof(size_t));
if (copybytes > size)
copybytes = size;
if ((new = cl__malloc(size, file, line)) == NULL)
goto out;
memcpy(new, p, copybytes);
cl__free(p);
if (p) {
memcpy(new, p, copybytes);
cl__free(p);
}
out:
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