From 3a0c61d6ada8dffb0506163b6be01c811d6fc2a9 Mon Sep 17 00:00:00 2001 From: Tim Felgentreff <timfelgentreff@gmail.com> Date: Wed, 27 Apr 2022 21:22:37 +0200 Subject: [PATCH] don't overallocate mng array --- src/unit/script_unittype.cpp | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/unit/script_unittype.cpp b/src/unit/script_unittype.cpp index 5788bec17..565a81bed 100644 --- a/src/unit/script_unittype.cpp +++ b/src/unit/script_unittype.cpp @@ -607,7 +607,14 @@ static int CclDefineUnitType(lua_State *l) LuaError(l, "incorrect argument"); } const int subargs = lua_rawlen(l, -1); - type->Portrait.Num = subargs; + int number = 0; + for (int k = 0; k < subargs; ++k) { + const char *s = LuaToString(l, -1, k + 1); + if (strcmp("talking", s)) { + number++; + } + } + type->Portrait.Num = number; type->Portrait.Talking = 0; type->Portrait.Files = new std::string[type->Portrait.Num]; type->Portrait.Mngs = new Mng *[type->Portrait.Num]; @@ -616,7 +623,6 @@ static int CclDefineUnitType(lua_State *l) const char *s = LuaToString(l, -1, k + 1); if (!strcmp("talking", s)) { type->Portrait.Talking = k; - type->Portrait.Num--; } else { type->Portrait.Files[k - (type->Portrait.Talking ? 1 : 0)] = s; }