From bd820638b5f92624b4777d4737479e96751af6d5 Mon Sep 17 00:00:00 2001 From: Nathan Fisher Date: Mon, 14 Aug 2023 23:42:09 -0400 Subject: [PATCH] Replace several uses of `malloc` with `calloc` --- .gitignore | 1 + haggis.c | 8 ++++---- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/.gitignore b/.gitignore index fde95b3..5471b3c 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,7 @@ haggis config.mk test/output/ +test/ *.o *.a *.so diff --git a/haggis.c b/haggis.c index 0249bb0..62a7656 100644 --- a/haggis.c +++ b/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);