diff --git a/src/logic/scripting/lua/libs/libutf8.cpp b/src/logic/scripting/lua/libs/libutf8.cpp index 15fc54e92..163f07e4e 100644 --- a/src/logic/scripting/lua/libs/libutf8.cpp +++ b/src/logic/scripting/lua/libs/libutf8.cpp @@ -57,7 +57,12 @@ static int l_sub(lua::State* L) { if (lua::gettop(L) >= 3) { end = std::max(0, static_cast(lua::tointeger(L, 3) - 1)); } - return lua::pushstring(L, util::u32str2str_utf8(string.substr(start, end))); + return lua::pushstring( + L, + util::u32str2str_utf8( + string.substr(start, (end >= start ? end - start + 1 : 0)) + ) + ); } static int l_upper(lua::State* L) {