From 9a0c5b2023c3712f6dd0ffb194a8c4a5497d64fa Mon Sep 17 00:00:00 2001 From: Nomango Date: Tue, 7 Apr 2020 16:35:26 +0800 Subject: [PATCH] [deploy] fix minor bugs --- src/kiwano/core/String.cpp | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/src/kiwano/core/String.cpp b/src/kiwano/core/String.cpp index 0c4cd37e..c81c6a51 100644 --- a/src/kiwano/core/String.cpp +++ b/src/kiwano/core/String.cpp @@ -40,7 +40,7 @@ String Format(const char* format, ...) const auto len = static_cast(::_vscprintf(format, args) + 1); if (len) { - result.resize(len); + result.resize(len - 1); ::_vsnprintf_s(&result[0], len, len, format, args); } va_end(args); @@ -59,7 +59,7 @@ WideString Format(const wchar_t* format, ...) const auto len = static_cast(::_vscwprintf(format, args) + 1); if (len) { - result.resize(len); + result.resize(len - 1); ::_vsnwprintf_s(&result[0], len, len, format, args); } va_end(args); @@ -72,13 +72,13 @@ String ToNarrow(const WideString& str) if (str.empty()) return String(); - int chars_num = ::WideCharToMultiByte(CP_ACP, 0, str.c_str(), -1, NULL, 0, NULL, NULL); - if (chars_num) + int len = ::WideCharToMultiByte(CP_ACP, 0, str.c_str(), -1, NULL, 0, NULL, NULL); + if (len > 0) { String result; - result.resize(chars_num); + result.resize(len - 1); - ::WideCharToMultiByte(CP_ACP, 0, str.c_str(), -1, &result[0], chars_num, NULL, NULL); + ::WideCharToMultiByte(CP_ACP, 0, str.c_str(), -1, &result[0], len, NULL, NULL); return result; } return String(); @@ -89,13 +89,13 @@ WideString ToWide(const String& str) if (str.empty()) return WideString(); - int chars_num = ::MultiByteToWideChar(CP_ACP, 0, str.c_str(), -1, NULL, 0); - if (chars_num) + int len = ::MultiByteToWideChar(CP_ACP, 0, str.c_str(), -1, NULL, 0); + if (len > 0) { WideString result; - result.resize(chars_num); + result.resize(len - 1); - ::MultiByteToWideChar(CP_ACP, 0, str.c_str(), -1, &result[0], chars_num); + ::MultiByteToWideChar(CP_ACP, 0, str.c_str(), -1, &result[0], len); return result; } return WideString();