From a9c5365ccb12755318f2c71cb6de3ffded378d91 Mon Sep 17 00:00:00 2001 From: jfrickmann Date: Thu, 9 Dec 2021 21:09:01 -0500 Subject: [PATCH] Truncate Mixer Lua script input and output names to 6 chars --- radio/src/lua/interface.cpp | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/radio/src/lua/interface.cpp b/radio/src/lua/interface.cpp index a638bc365..9fa691dc5 100644 --- a/radio/src/lua/interface.cpp +++ b/radio/src/lua/interface.cpp @@ -190,7 +190,12 @@ void luaGetInputs(ScriptInputsOutputs & sid) case 0: luaL_checktype(lsScripts, -2, LUA_TNUMBER); // key is number luaL_checktype(lsScripts, -1, LUA_TSTRING); // value is string - lua_xmove(lsScripts, L, 1); // To preserve the string value, move it to the main stack + { // To preserve the string value, truncate to 6 chars and move it to the main stack + char str[7] = {0}; + strncpy(str, lua_tostring(lsScripts, -1), 6); + lua_pushstring(L, &str[0]); + } + lua_pop(lsScripts, 1); lua_pushnil(lsScripts); // Keep the stack balanced lua_insert(L, -2); // Keep the coroutine at the top of the main stack si->name = lua_tostring(L, -2); @@ -248,11 +253,15 @@ void luaGetOutputs(ScriptInputsOutputs & sid) luaL_checktype(lsScripts, -2, LUA_TNUMBER); // key is number luaL_checktype(lsScripts, -1, LUA_TSTRING); // value is string if (sid.outputsCount < MAX_SCRIPT_OUTPUTS) { - lua_xmove(lsScripts, L, 1); // To preserve the string value, move it to the main stack - lua_insert(L, -2); // Keep the coroutine at the top of the main stack + // To preserve the string value, truncate to 6 chars and move it to the main stack + char str[7] = {0}; + strncpy(str, lua_tostring(lsScripts, -1), 6); + lua_pushstring(L, &str[0]); + // Keep the coroutine at the top of the main stack + lua_insert(L, -2); sid.outputs[sid.outputsCount++].name = lua_tostring(L, -2); } - else lua_pop(lsScripts, 1); + lua_pop(lsScripts, 1); } } #endif