Skip to content

Commit

Permalink
Merge pull request #143 from visitorckw/fix-calloc
Browse files Browse the repository at this point in the history
Fix calloc to return NULL on malloc failure
  • Loading branch information
jserv authored Jul 21, 2024
2 parents cb34939 + ecd7599 commit aab5755
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 2 deletions.
3 changes: 3 additions & 0 deletions lib/c.c
Original file line number Diff line number Diff line change
Expand Up @@ -654,6 +654,9 @@ void *malloc(int size)
void *calloc(int n, int size)
{
char *p = malloc(n * size);

if (!p)
return NULL;
for (int i = 0; i < n * size; i++)
p[i] = 0;
return p;
Expand Down
2 changes: 1 addition & 1 deletion tests/snapshots/fib.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion tests/snapshots/hello.json

Large diffs are not rendered by default.

0 comments on commit aab5755

Please sign in to comment.