tcc_mallocz: clear with memset only if nonzero size

Even if non-NULL, dereferencing the pointer from malloc(0)
or passing it to memset() may invoke undefined behavior.
This commit is contained in:
John Scott 2020-10-16 21:20:33 -04:00
parent 72b520e709
commit 558c6f56e2
No known key found for this signature in database
GPG key ID: 72BC7148C0AB2DA7

View file

@ -245,7 +245,8 @@ PUB_FUNC void *tcc_mallocz(unsigned long size)
{
void *ptr;
ptr = tcc_malloc(size);
memset(ptr, 0, size);
if (size)
memset(ptr, 0, size);
return ptr;
}