Replace several uses of malloc
with calloc
This commit is contained in:
parent
b0c2c0c8ac
commit
bd820638b5
2 changed files with 5 additions and 4 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -1,6 +1,7 @@
|
|||
haggis
|
||||
config.mk
|
||||
test/output/
|
||||
test/
|
||||
*.o
|
||||
*.a
|
||||
*.so
|
||||
|
|
8
haggis.c
8
haggis.c
|
@ -315,7 +315,7 @@ int haggis_file_init(char *path, haggis_file *hf, haggis_algorithm a) {
|
|||
}
|
||||
hf->len.val = (uint64_t)len;
|
||||
rewind(f);
|
||||
hf->data = malloc((size_t)len);
|
||||
hf->data = calloc(1, (size_t)len);
|
||||
if (fread(hf->data, 1, (size_t)len, f) != (size_t)len) {
|
||||
free(hf->data);
|
||||
fclose(f);
|
||||
|
@ -346,7 +346,7 @@ int haggis_load_file(FILE *stream, haggis_file *f) {
|
|||
return 1;
|
||||
if (haggis_load_cksum(stream, &f->cksum) != 0)
|
||||
return 1;
|
||||
f->data = malloc((size_t)f->len.val);
|
||||
f->data = calloc(1, (size_t)f->len.val);
|
||||
if (f->data == NULL)
|
||||
return -1;
|
||||
int res = fread(f->data, 1, (size_t)f->len.val, stream);
|
||||
|
@ -382,7 +382,7 @@ int haggis_load_filename(FILE *stream, haggis_filename *n) {
|
|||
len.val = 0;
|
||||
if (fread(len.bytes, 1, 2, stream) != 2) return 2;
|
||||
n->len = len;
|
||||
name = malloc((size_t)len.val);
|
||||
name = calloc(1, (size_t)len.val);
|
||||
if (name == NULL) return -1;
|
||||
if (fread(name, 1, (size_t)len.val, stream) != (size_t)len.val) {
|
||||
free(name);
|
||||
|
@ -528,7 +528,7 @@ haggis_node* haggis_create_node(char *file, haggis_algorithm a, haggis_hardlink_
|
|||
int res;
|
||||
haggis_node *node;
|
||||
|
||||
node = malloc(sizeof(haggis_node));
|
||||
node = calloc(1, sizeof(haggis_node));
|
||||
if (node == NULL) return NULL;
|
||||
if (stat(file, st) != 0) {
|
||||
free(node);
|
||||
|
|
Loading…
Add table
Reference in a new issue