diff --git a/src/fpk.c b/src/fpk.c index 683e74d..8ee9ef1 100644 --- a/src/fpk.c +++ b/src/fpk.c @@ -113,18 +113,23 @@ struct fpk *fpk_open(const char *path) goto fail; strtab_size = dir_offset - strtab_offset; - fpk->strtab = malloc((size_t)strtab_size); - if (fpk->strtab == NULL) - goto fail; - if (fpk_fseek64(fpk->file, strtab_offset) != 0) - goto fail; - if (fread(fpk->strtab, 1, (size_t)strtab_size, fpk->file) != - strtab_size) - goto fail; + if (strtab_size > 0) { + fpk->strtab = malloc((size_t)strtab_size); + if (fpk->strtab == NULL) + goto fail; + if (fpk_fseek64(fpk->file, strtab_offset) != 0) + goto fail; + if (fread(fpk->strtab, 1, (size_t)strtab_size, fpk->file) != + strtab_size) + goto fail; + } - fpk->entries = malloc((size_t)fpk->entry_count * sizeof(fpk_entry_t)); - if (fpk->entries == NULL) - goto fail; + if (fpk->entry_count > 0) { + fpk->entries = malloc( + (size_t)fpk->entry_count * sizeof(fpk_entry_t)); + if (fpk->entries == NULL) + goto fail; + } if (fpk_fseek64(fpk->file, dir_offset) != 0) goto fail; for (i = 0; i < fpk->entry_count; i++) {