From 8dbe32cb8e2efcc6a746db873ea176818a8d75d6 Mon Sep 17 00:00:00 2001 From: yyc12345 Date: Tue, 12 Aug 2025 16:05:11 +0800 Subject: [PATCH] fix: fix fatal error in encoding/iconv. - fix the size of input data error (forget mul with the size of unit) - fix the wrong code name for UTF16 and UTF32. - fix wrong assign for `outbytesleft`. --- src/yycc/encoding/iconv.cpp | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/yycc/encoding/iconv.cpp b/src/yycc/encoding/iconv.cpp index 657810b..2e97332 100644 --- a/src/yycc/encoding/iconv.cpp +++ b/src/yycc/encoding/iconv.cpp @@ -151,7 +151,7 @@ namespace yycc::encoding::iconv { // resize for container and its variables str_to.resize(str_to.size() + ICONV_INC_LEN); - outbytesleft = str_to.size(); + outbytesleft += ICONV_INC_LEN; // assign new outbuf from failed position outbuf = reinterpret_cast(str_to.data()) + len; @@ -193,15 +193,15 @@ namespace yycc::encoding::iconv { constexpr auto WCHAR_CODENAME_LITERAL = "WCHAR_T"sv; constexpr auto UTF16_CODENAME_LITERAL = #if defined(YYCC_ENDIAN_LITTLE) - "UTF16LE"sv; + "UTF-16LE"sv; #else - "UTF16BE"sv; + "UTF-16BE"sv; #endif constexpr auto UTF32_CODENAME_LITERAL = #if defined(YYCC_ENDIAN_LITTLE) - "UTF32LE"sv; + "UTF-32LE"sv; #else - "UTF32BE"sv; + "UTF-32BE"sv; #endif // TODO: @@ -210,7 +210,7 @@ namespace yycc::encoding::iconv { // We call them VecString and VecStringView, and use them in "iconv_kernel" instead of real std::vector. // They exposed interface are std::vector-like but its inner is std::basic_string and std::basic_string_view. #define USER_CONVFN(src_char_type, dst_char_type) \ - auto rv = iconv_kernel(this->token, reinterpret_cast(src.data()), src.size()); \ + auto rv = iconv_kernel(this->token, reinterpret_cast(src.data()), src.size() * sizeof(src_char_type)); \ if (rv.has_value()) { \ const auto& dst = rv.value(); \ if constexpr (sizeof(dst_char_type) > 1u) { \