aboutsummaryrefslogtreecommitdiff
path: root/io/param.c
diff options
context:
space:
mode:
Diffstat (limited to 'io/param.c')
-rw-r--r--io/param.c10
1 files changed, 6 insertions, 4 deletions
diff --git a/io/param.c b/io/param.c
index 477df28..a57b183 100644
--- a/io/param.c
+++ b/io/param.c
@@ -77,7 +77,8 @@ ParamChunkData *get_param_chunk_data(FILE *fp, ParamChunkInfo *info) {
pcd->data = (char *)malloc(info->length);
pcd->fp = fmemopen(pcd->data, info->length, "r");
assert(fseeko(fp, info->offset, SEEK_SET) == 0);
- assert(fread(pcd->data, 1, info->length, fp) == (size_t)info->length);
+ if (fread(pcd->data, 1, info->length, fp) != (size_t)info->length)
+ return NULL;
return pcd;
}
@@ -239,6 +240,7 @@ int nerv_param_file_write_chunkdata(lua_State *L) {
int nerv_param_file_get_chunkdata(lua_State *L) {
ParamFileHandle *pfh;
ParamChunkInfo *pci;
+ ParamChunkData *pcd;
const char *id = luaL_checkstring(L, 2);
lua_getfield(L, 1, "handle");
@@ -252,9 +254,9 @@ int nerv_param_file_get_chunkdata(lua_State *L) {
return 0;
lua_getfield(L, -1, "chunk");
pci = luaT_checkudata(L, -1, nerv_param_chunk_info_tname);
-
- luaT_pushudata(L, get_param_chunk_data(pfh->fp, pci),
- nerv_param_chunk_data_tname);
+ if (!(pcd = get_param_chunk_data(pfh->fp, pci)))
+ nerv_error(L, "unexpected end of file");
+ luaT_pushudata(L, pcd, nerv_param_chunk_data_tname);
return 1;
}