Check for NULL after allocating

This commit is contained in:
Nathan Fisher 2023-07-25 19:50:46 -04:00
parent e97feb1e3d
commit 8ebaefd712

View file

@ -247,6 +247,8 @@ int haggis_load_file(FILE *stream, union haggis_ft *ft) {
if (haggis_load_cksum(stream, ft->file->cksum) != 0)
return 1;
u8 *data = malloc((size_t)len.val);
if (data == NULL)
return -1;
int res = fread(data, 1, (size_t)ft->file->len.val, stream);
if (res != (size_t)ft->file->len.val) {
free(ft);
@ -333,6 +335,8 @@ int haggis_load_filename(FILE *stream, struct haggis_filename *n) {
return 2;
n->len = len;
name = malloc((size_t)len.val);
if (name == NULL)
return -1;
if (fread(name, 1, (size_t)len.val, stream) != (size_t)len.val) {
free(name);
return 2;
@ -383,6 +387,8 @@ enum haggis_typeflag haggis_filetype_from_mode(union u16 mode) {
struct haggis_node* haggis_create_node(char *file) {
struct haggis_node *node = malloc(sizeof(struct haggis_node));
if (node == NULL)
return NULL;
// todo
return node;
}