Skip to content

Commit

Permalink
Revert "smalloc: smalloc() already clears memory, scalloc() need not …
Browse files Browse the repository at this point in the history
…do it again"

Originally:
smalloc cleared the buffer
scalloc did not need to clear the differ

Later: 9c3e13e
smalloc was changed to not clear the buffer
scalloc was not updated to clear the buffer when the above smalloc
change was made

Originally smalloc always cleared the buffer. So it wasn't necessary for
scalloc to clear it again. But later on smalloc was changed to no longer
clear the buffer but scalloc was not changed back to clear the buffer.

Reverting this commit makes scalloc clear the buffer again.

This reverts commit a640ed3.

Fixes: #1772
Signed-off-by: Vincent Fu <[email protected]>
  • Loading branch information
vincentkfu committed Jun 6, 2024
1 parent 695ab5c commit eb7fe45
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion smalloc.c
Original file line number Diff line number Diff line change
Expand Up @@ -566,7 +566,13 @@ void *smalloc(size_t size)

void *scalloc(size_t nmemb, size_t size)
{
return smalloc(nmemb * size);
void *ret;

ret = smalloc(nmemb * size);
if (ret)
memset(ret, 0, nmemb * size);

return ret;
}

char *smalloc_strdup(const char *str)
Expand Down

0 comments on commit eb7fe45

Please sign in to comment.