Browse Source

Replace VLA with static array

master
Jessica James 3 years ago
parent
commit
a14b1a4ad8
  1. 4
      src/include/jessilib/unicode.hpp
  2. 6
      src/test/http_query.cpp

4
src/include/jessilib/unicode.hpp

@ -229,9 +229,9 @@ std::pair<bool, std::string> ustring_to_mbstring(std::basic_string_view<CharT> i
while ((decode = decode_codepoint(in_string)).units != 0) { while ((decode = decode_codepoint(in_string)).units != 0) {
in_string.remove_prefix(decode.units); in_string.remove_prefix(decode.units);
char buffer[MB_CUR_MAX]; // MB_LEN_MAX char buffer[MB_LEN_MAX]; // MB_LEN_MAX is constant, MB_CUR_MAX is not, and C++ doesn't have VLAs
size_t bytes_written = std::c32rtomb(buffer, decode.codepoint, &mbstate); size_t bytes_written = std::c32rtomb(buffer, decode.codepoint, &mbstate);
if (bytes_written > MB_CUR_MAX) { if (bytes_written > MB_LEN_MAX) {
// Invalid codepoint; return // Invalid codepoint; return
result.first = false; result.first = false;
return result; return result;

6
src/test/http_query.cpp

@ -29,9 +29,9 @@ constexpr std::u8string query_constexpr(std::u8string_view in_expression) {
jessilib::deserialize_http_query(result); jessilib::deserialize_http_query(result);
return result; return result;
} }
ASSERT_COMPILES_CONSTEXPR(return query_constexpr("test"s) == "test"s); ASSERT_COMPILES_CONSTEXPR(return query_constexpr(u8"test"s) == u8"test"s);
ASSERT_COMPILES_CONSTEXPR(return query_constexpr("first+second"s) == "first second"s); ASSERT_COMPILES_CONSTEXPR(return query_constexpr(u8"first+second"s) == u8"first second"s);
ASSERT_COMPILES_CONSTEXPR(return query_constexpr("first%20second"s) == "first second"s); ASSERT_COMPILES_CONSTEXPR(return query_constexpr(u8"first%20second"s) == u8"first second"s);
#endif // __cpp_lib_constexpr_string #endif // __cpp_lib_constexpr_string
using char_types = ::testing::Types</*char,*/ char8_t, char16_t, char32_t>; using char_types = ::testing::Types</*char,*/ char8_t, char16_t, char32_t>;

Loading…
Cancel
Save