From 323c3ca2101238a7fd251103634df5e5d415a8a7 Mon Sep 17 00:00:00 2001 From: Shepherd Date: Fri, 24 Jun 2022 07:43:54 -0400 Subject: [PATCH] =?UTF-8?q?=F0=9F=9B=A0=20Prevent=20non-zero=20default=20i?= =?UTF-8?q?nitialization=20for=20result=20types?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- include/sol/load_result.hpp | 6 ++++-- include/sol/protected_function_result.hpp | 2 +- include/sol/unsafe_function_result.hpp | 6 ++++-- 3 files changed, 9 insertions(+), 5 deletions(-) diff --git a/include/sol/load_result.hpp b/include/sol/load_result.hpp index 60c14b65..07c119f8 100644 --- a/include/sol/load_result.hpp +++ b/include/sol/load_result.hpp @@ -39,7 +39,7 @@ namespace sol { load_status err; public: - load_result() noexcept = default; + load_result() noexcept : load_result(nullptr) {} load_result(lua_State* Ls, int stackindex = -1, int retnum = 0, int popnum = 0, load_status lerr = load_status::ok) noexcept : L(Ls), index(stackindex), returncount(retnum), popcount(popnum), err(lerr) { } @@ -142,7 +142,9 @@ namespace sol { }; ~load_result() { - stack::remove(L, index, popcount); + if (L != nullptr) { + stack::remove(L, index, popcount); + } } }; } // namespace sol diff --git a/include/sol/protected_function_result.hpp b/include/sol/protected_function_result.hpp index d806177e..afcbc1c2 100644 --- a/include/sol/protected_function_result.hpp +++ b/include/sol/protected_function_result.hpp @@ -54,7 +54,7 @@ namespace sol { typedef std::reverse_iterator reverse_iterator; typedef std::reverse_iterator const_reverse_iterator; - protected_function_result() noexcept = default; + protected_function_result() noexcept : protected_function_result(nullptr) {} protected_function_result(lua_State* Ls, int idx = -1, int retnum = 0, int popped = 0, call_status pferr = call_status::ok) noexcept : L(Ls), index(idx), returncount(retnum), popcount(popped), err(pferr) { } diff --git a/include/sol/unsafe_function_result.hpp b/include/sol/unsafe_function_result.hpp index d340f0de..c5e976ff 100644 --- a/include/sol/unsafe_function_result.hpp +++ b/include/sol/unsafe_function_result.hpp @@ -50,7 +50,7 @@ namespace sol { typedef std::reverse_iterator reverse_iterator; typedef std::reverse_iterator const_reverse_iterator; - unsafe_function_result() noexcept = default; + unsafe_function_result() noexcept : unsafe_function_result(nullptr) {} unsafe_function_result(lua_State* Ls, int idx = -1, int retnum = 0) noexcept : L(Ls), index(idx), returncount(retnum) { } @@ -158,7 +158,9 @@ namespace sol { returncount = 0; } ~unsafe_function_result() { - lua_pop(L, returncount); + if (L != nullptr) { + lua_pop(L, returncount); + } } };