From 87b592685ad8c62746c53bdba5502fed98a0bdbd Mon Sep 17 00:00:00 2001 From: Otto Moerbeek Date: Fri, 1 Apr 2022 14:48:05 +0200 Subject: [PATCH] Coverity: 1419402 Uncaught exception Catch any exception that might be thrown when (copy) constructing an object. As the push method is declared `noexcept` we cannot have that. --- ext/luawrapper/include/LuaContext.hpp | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/ext/luawrapper/include/LuaContext.hpp b/ext/luawrapper/include/LuaContext.hpp index 9f8d473fb7..ad6c86e556 100644 --- a/ext/luawrapper/include/LuaContext.hpp +++ b/ext/luawrapper/include/LuaContext.hpp @@ -1639,12 +1639,18 @@ private: // writing structure for this type into the registry checkTypeRegistration(state, &typeid(TType)); + try { + // creating the object + // lua_newuserdata allocates memory in the internals of the lua library and returns it so we can fill it + // and that's what we do with placement-new + const auto pointerLocation = static_cast(lua_newuserdata(state, sizeof(TType))); + new (pointerLocation) TType(std::forward(value)); + } + catch (...) { + Pusher::push(state, std::current_exception()).release(); + luaError(state); + } - // creating the object - // lua_newuserdata allocates memory in the internals of the lua library and returns it so we can fill it - // and that's what we do with placement-new - const auto pointerLocation = static_cast(lua_newuserdata(state, sizeof(TType))); - new (pointerLocation) TType(std::forward(value)); PushedObject obj{state, 1}; // creating the metatable (over the object on the stack) -- 2.47.2