diff --git a/sol/stack_get.hpp b/sol/stack_get.hpp index 6693bc01..439f4fb7 100644 --- a/sol/stack_get.hpp +++ b/sol/stack_get.hpp @@ -454,13 +454,14 @@ namespace stack { template struct getter> { - static std::basic_string get(lua_State* L, int index, record& tracking) { + typedef std::basic_string S; + static S get(lua_State* L, int index, record& tracking) { typedef std::conditional_t Ch; - typedef std::allocator_traits::rebind_alloc ChAl; + typedef typename std::allocator_traits::template rebind_alloc ChAl; typedef std::char_traits ChTraits; getter> g; (void)g; - return g.get_into>(L, index, tracking); + return g.template get_into(L, index, tracking); } }; diff --git a/sol/unicode.hpp b/sol/unicode.hpp index 1a73a4ee..1c7f673c 100644 --- a/sol/unicode.hpp +++ b/sol/unicode.hpp @@ -2,6 +2,7 @@ #include "string_view.hpp" #include +#include namespace sol { // Everything here was lifted pretty much straight out of @@ -18,7 +19,7 @@ namespace sol { }; inline const string_view& to_string(error_code ec) { - const string_view arr[4] = { + static const string_view arr[4] = { "ok", "invalid code points", "invalid code unit", @@ -172,9 +173,14 @@ namespace sol { } template - inline decoded_result utf8_to_code_point(It it, It) { + inline decoded_result utf8_to_code_point(It it, It last) { decoded_result dr; - + if (it == last) { + dr.next = it; + dr.error = error_code::sequence_too_short; + return dr; + } + unsigned char b0 = *it; std::size_t length = unicode_detail::sequence_length(b0); @@ -200,7 +206,7 @@ namespace sol { ++it; std::array b; b[0] = b0; - for (int i = 1; i < length; ++i) { + for (std::size_t i = 1; i < length; ++i) { b[i] = *it; if (!is_continuation(b[i])) { dr.error = error_code::invalid_code_unit; @@ -245,8 +251,13 @@ namespace sol { } template - inline decoded_result utf16_to_code_point(It it, It) { + inline decoded_result utf16_to_code_point(It it, It last) { decoded_result dr; + if (it == last) { + dr.next = it; + dr.error = error_code::sequence_too_short; + return dr; + } char16_t lead = static_cast(*it); @@ -278,8 +289,13 @@ namespace sol { } template - inline decoded_result utf32_to_code_point(It it, It) { + inline decoded_result utf32_to_code_point(It it, It last) { decoded_result dr; + if (it == last) { + dr.next = it; + dr.error = error_code::sequence_too_short; + return dr; + } dr.codepoint = static_cast(*it); dr.next = ++it; dr.error = error_code::ok;