From 563284f6f1c578f41443073de9b302f729523e65 Mon Sep 17 00:00:00 2001 From: Habu Date: Thu, 18 Jul 2024 08:30:43 +0900 Subject: [PATCH] =?UTF-8?q?[Fix]=20=E3=82=A8=E3=83=A9=E3=83=BC=E3=83=AC?= =?UTF-8?q?=E3=83=9D=E3=83=BC=E3=83=88=E3=81=AE=E6=96=87=E5=AD=97=E5=8C=96?= =?UTF-8?q?=E3=81=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit システムロケールがUTF-8のWindows環境において、STLが出力する日本語の例外 メッセージの文字コードはUTF-8となる。しかし、エラーレポートのコードでは 文字コードはSJISであることを想定しており、UTF-8をSJISとみなして文字 コードの変換を行ってしまうため文字化けが発生する。 guess_convert_to_system_encoding 関数を通すことでメッセージを一旦SJISに 統一することで、システムロケールがSJISでもUTF-8でも正しく動作するように する。 --- src/main-win/main-win-exception.cpp | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/main-win/main-win-exception.cpp b/src/main-win/main-win-exception.cpp index f0eedc1750..90d929c7cd 100644 --- a/src/main-win/main-win-exception.cpp +++ b/src/main-win/main-win-exception.cpp @@ -1,4 +1,5 @@ #include "main-win/main-win-exception.h" +#include "locale/japanese.h" #include "main-win/main-win-utils.h" #include "net/report-error.h" #include @@ -15,7 +16,13 @@ void handle_unexpected_exception(const std::exception &e) { constexpr auto caption = _(L"予期しないエラー!", L"Unexpected error!"); - const std::string msg = e.what(); + std::string msg = e.what(); +#ifdef JP + // 例外メッセージがUTF-8の場合一旦SJISに変換する(SJISの場合はそのまま) + const auto msg_len = guess_convert_to_system_encoding(msg.data(), msg.size()); + msg.erase(msg_len); +#endif + const auto first_line = msg.substr(0, msg.find('\n')); #if !defined(DISABLE_NET)