From a14b1a4ad828f981644f709d7a7a528810dc8564 Mon Sep 17 00:00:00 2001 From: Jessica James Date: Sun, 12 Dec 2021 19:22:01 -0600 Subject: [PATCH] Replace VLA with static array --- src/include/jessilib/unicode.hpp | 4 ++-- src/test/http_query.cpp | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/include/jessilib/unicode.hpp b/src/include/jessilib/unicode.hpp index 674f69b..5b2897b 100644 --- a/src/include/jessilib/unicode.hpp +++ b/src/include/jessilib/unicode.hpp @@ -229,9 +229,9 @@ std::pair ustring_to_mbstring(std::basic_string_view i while ((decode = decode_codepoint(in_string)).units != 0) { 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); - if (bytes_written > MB_CUR_MAX) { + if (bytes_written > MB_LEN_MAX) { // Invalid codepoint; return result.first = false; return result; diff --git a/src/test/http_query.cpp b/src/test/http_query.cpp index 7337c5d..e13bb3b 100644 --- a/src/test/http_query.cpp +++ b/src/test/http_query.cpp @@ -29,9 +29,9 @@ constexpr std::u8string query_constexpr(std::u8string_view in_expression) { jessilib::deserialize_http_query(result); return result; } -ASSERT_COMPILES_CONSTEXPR(return query_constexpr("test"s) == "test"s); -ASSERT_COMPILES_CONSTEXPR(return query_constexpr("first+second"s) == "first second"s); -ASSERT_COMPILES_CONSTEXPR(return query_constexpr("first%20second"s) == "first second"s); +ASSERT_COMPILES_CONSTEXPR(return query_constexpr(u8"test"s) == u8"test"s); +ASSERT_COMPILES_CONSTEXPR(return query_constexpr(u8"first+second"s) == u8"first second"s); +ASSERT_COMPILES_CONSTEXPR(return query_constexpr(u8"first%20second"s) == u8"first second"s); #endif // __cpp_lib_constexpr_string using char_types = ::testing::Types;