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:
parent
72b520e709
commit
558c6f56e2
1 changed files with 2 additions and 1 deletions
3
libtcc.c
3
libtcc.c
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue