Skip to content

Commit aab5755

Browse files
authored
Merge pull request #143 from visitorckw/fix-calloc
Fix calloc to return NULL on malloc failure
2 parents cb34939 + ecd7599 commit aab5755

File tree

3 files changed

+5
-2
lines changed

3 files changed

+5
-2
lines changed

lib/c.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -654,6 +654,9 @@ void *malloc(int size)
654654
void *calloc(int n, int size)
655655
{
656656
char *p = malloc(n * size);
657+
658+
if (!p)
659+
return NULL;
657660
for (int i = 0; i < n * size; i++)
658661
p[i] = 0;
659662
return p;

tests/snapshots/fib.json

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

tests/snapshots/hello.json

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

0 commit comments

Comments
 (0)