Skip to content

Commit

Permalink
Merge pull request DreamAndDead#44 from ByteMansion/patch-1
Browse files Browse the repository at this point in the history
memset cause core dump
  • Loading branch information
张大伟 authored Jul 1, 2019
2 parents 4aa18f4 + e7ade10 commit 3eeb67a
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion chapter2/code/calloc.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@ void* another_calloc(size_t nmemb, size_t size) {
/* a good way to check overflow or not */
if (nmemb == buf_size / size) {
void* ptr = malloc(buf_size);
memset(ptr, 0, buf_size);
if(ptr != NULL) {
memset(ptr, 0, buf_size);
}
return ptr;
}
return NULL;
Expand Down

0 comments on commit 3eeb67a

Please sign in to comment.