From e28c527bfa8fb8fbe34cbb887a3d2418c60a4513 Mon Sep 17 00:00:00 2001 From: Alexandre LittleWhite Laurent Date: Thu, 19 Jul 2018 21:11:47 +0200 Subject: [PATCH 1/2] Fix missing return value --- src/core/frontend/applets/swkbd.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/core/frontend/applets/swkbd.cpp b/src/core/frontend/applets/swkbd.cpp index 335d99d16..5c64defe8 100644 --- a/src/core/frontend/applets/swkbd.cpp +++ b/src/core/frontend/applets/swkbd.cpp @@ -130,6 +130,7 @@ ValidationError SoftwareKeyboard::Finalize(const std::string& text, u8 button) { return error; } data = {text, button}; + return ValidationError::None; } void DefaultKeyboard::Setup(const Frontend::KeyboardConfig* config) { From 578b08c53b23a3842e0d766ef7822a0e9e8b1138 Mon Sep 17 00:00:00 2001 From: Alexandre LittleWhite Laurent Date: Fri, 20 Jul 2018 19:50:33 +0200 Subject: [PATCH 2/2] Truncating UTF16 text before converting them toUTF8 --- src/core/hle/applets/swkbd.cpp | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/src/core/hle/applets/swkbd.cpp b/src/core/hle/applets/swkbd.cpp index e7ea84572..94a4ab339 100644 --- a/src/core/hle/applets/swkbd.cpp +++ b/src/core/hle/applets/swkbd.cpp @@ -148,8 +148,13 @@ Frontend::KeyboardConfig SoftwareKeyboard::ToFrontendConfig( frontend_config.multiline_mode = config.multiline; frontend_config.max_text_length = config.max_text_length; frontend_config.max_digits = config.max_digits; - std::u16string buffer(config.hint_text.size(), 0); - std::memcpy(buffer.data(), config.hint_text.data(), config.hint_text.size() * sizeof(u16)); + + size_t text_size = config.hint_text.size(); + const auto text_end = std::find(config.hint_text.begin(), config.hint_text.end(), u'\0'); + if (text_end != config.hint_text.end()) + text_size = std::distance(config.hint_text.begin(), text_end); + std::u16string buffer(text_size, 0); + std::memcpy(buffer.data(), config.hint_text.data(), text_size * sizeof(u16)); frontend_config.hint_text = Common::UTF16ToUTF8(buffer); frontend_config.has_custom_button_text = !std::all_of(config.button_text.begin(), config.button_text.end(), @@ -158,8 +163,13 @@ Frontend::KeyboardConfig SoftwareKeyboard::ToFrontendConfig( }); if (frontend_config.has_custom_button_text) { for (const auto& text : config.button_text) { - buffer.resize(text.size()); - std::memcpy(buffer.data(), text.data(), text.size() * sizeof(u16)); + text_size = text.size(); + const auto text_end = std::find(text.begin(), text.end(), u'\0'); + if (text_end != text.end()) + text_size = std::distance(text.begin(), text_end); + + buffer.resize(text_size); + std::memcpy(buffer.data(), text.data(), text_size * sizeof(u16)); frontend_config.button_text.push_back(Common::UTF16ToUTF8(buffer)); } }