From e158206e5505ba4933384cc4767d56de2dff84bd Mon Sep 17 00:00:00 2001 From: Monster Iestyn Date: Tue, 27 Nov 2018 23:06:31 +0000 Subject: [PATCH] backport string len tweaks I made to LUA_LoadLump in internal --- src/lua_script.c | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/src/lua_script.c b/src/lua_script.c index 3fb1960d..a079f57f 100644 --- a/src/lua_script.c +++ b/src/lua_script.c @@ -186,27 +186,30 @@ void LUA_LoadLump(UINT16 wad, UINT16 lump) { MYFILE f; char *name; + size_t len; f.wad = wad; f.size = W_LumpLengthPwad(wad, lump); f.data = Z_Malloc(f.size, PU_LUA, NULL); W_ReadLumpPwad(wad, lump, f.data); f.curpos = f.data; + len = strlen(wadfiles[wad]->filename); // length of file name + if (wadfiles[wad]->type == RET_LUA) { - name = malloc(strlen(wadfiles[wad]->filename)+1); + name = malloc(len+1); strcpy(name, wadfiles[wad]->filename); } else // If it's not a .lua file, copy the lump name in too. { lumpinfo_t *lump_p = &wadfiles[wad]->lumpinfo[lump]; - size_t length = strlen(wadfiles[wad]->filename) + 1 + strlen(lump_p->name2); // length of file name, '|', and lump name - name = malloc(length + 1); + len += 1 + strlen(lump_p->name2); // length of file name, '|', and lump name + name = malloc(len+1); sprintf(name, "%s|%s", wadfiles[wad]->filename, lump_p->name2); - name[length] = '\0'; + name[len] = '\0'; } - LUA_LoadFile(&f, name); + LUA_LoadFile(&f, name); // actually load file! free(name); Z_Free(f.data);