From 200e8f8dbb6ff07f2c08477203df4b84f3dd96ca Mon Sep 17 00:00:00 2001 From: Igor Zhukov Date: Sun, 24 Apr 2022 15:38:44 +0700 Subject: [PATCH 1/3] explicitly pass the system locale ID --- stl/src/syserror_import_lib.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/stl/src/syserror_import_lib.cpp b/stl/src/syserror_import_lib.cpp index 8f8046d48c..cb14af86c8 100644 --- a/stl/src/syserror_import_lib.cpp +++ b/stl/src/syserror_import_lib.cpp @@ -47,7 +47,7 @@ _NODISCARD size_t __CLRCALL_PURE_OR_STDCALL __std_system_error_allocate_message( // pre: *_Ptr_str == nullptr const unsigned long _Chars = FormatMessageA(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS, - nullptr, _Message_id, 0, reinterpret_cast(_Ptr_str), 0, nullptr); + nullptr, _Message_id, GetSystemDefaultLangID(), reinterpret_cast(_Ptr_str), 0, nullptr); return _CSTD __std_get_string_size_without_trailing_whitespace(*_Ptr_str, _Chars); } From 80e182fbb0607234f13cce86a12d71a234402c6e Mon Sep 17 00:00:00 2001 From: Igor Zhukov Date: Thu, 28 Apr 2022 12:26:53 +0700 Subject: [PATCH 2/3] use GetLocaleInfoEx instead of GetSystemDefaultLangID --- stl/src/syserror_import_lib.cpp | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/stl/src/syserror_import_lib.cpp b/stl/src/syserror_import_lib.cpp index cb14af86c8..cf4a9fd7d2 100644 --- a/stl/src/syserror_import_lib.cpp +++ b/stl/src/syserror_import_lib.cpp @@ -42,12 +42,18 @@ _NODISCARD size_t __CLRCALL_PURE_OR_STDCALL __std_get_string_size_without_traili _NODISCARD size_t __CLRCALL_PURE_OR_STDCALL __std_system_error_allocate_message( const unsigned long _Message_id, char** const _Ptr_str) noexcept { + DWORD _Lang_id; + const int _Ret = GetLocaleInfoEx(LOCALE_NAME_SYSTEM_DEFAULT, LOCALE_ILANGUAGE | LOCALE_RETURN_NUMBER, + reinterpret_cast(&_Lang_id), sizeof(_Lang_id) / sizeof(wchar_t)); + if (_Ret == 0) { + _Lang_id = 0; + } // convert to name of Windows error, return 0 for failure, otherwise return number of chars in buffer // __std_system_error_deallocate_message should be called even if 0 is returned // pre: *_Ptr_str == nullptr const unsigned long _Chars = FormatMessageA(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS, - nullptr, _Message_id, GetSystemDefaultLangID(), reinterpret_cast(_Ptr_str), 0, nullptr); + nullptr, _Message_id, _Lang_id, reinterpret_cast(_Ptr_str), 0, nullptr); return _CSTD __std_get_string_size_without_trailing_whitespace(*_Ptr_str, _Chars); } From 08354147db3d953c45c373fbf405fd2e78d6d0dd Mon Sep 17 00:00:00 2001 From: Igor Zhukov Date: Thu, 28 Apr 2022 13:48:46 +0700 Subject: [PATCH 3/3] move a comment to the top. --- stl/src/syserror_import_lib.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/stl/src/syserror_import_lib.cpp b/stl/src/syserror_import_lib.cpp index cf4a9fd7d2..88db626308 100644 --- a/stl/src/syserror_import_lib.cpp +++ b/stl/src/syserror_import_lib.cpp @@ -42,15 +42,15 @@ _NODISCARD size_t __CLRCALL_PURE_OR_STDCALL __std_get_string_size_without_traili _NODISCARD size_t __CLRCALL_PURE_OR_STDCALL __std_system_error_allocate_message( const unsigned long _Message_id, char** const _Ptr_str) noexcept { + // convert to name of Windows error, return 0 for failure, otherwise return number of chars in buffer + // __std_system_error_deallocate_message should be called even if 0 is returned + // pre: *_Ptr_str == nullptr DWORD _Lang_id; const int _Ret = GetLocaleInfoEx(LOCALE_NAME_SYSTEM_DEFAULT, LOCALE_ILANGUAGE | LOCALE_RETURN_NUMBER, reinterpret_cast(&_Lang_id), sizeof(_Lang_id) / sizeof(wchar_t)); if (_Ret == 0) { _Lang_id = 0; } - // convert to name of Windows error, return 0 for failure, otherwise return number of chars in buffer - // __std_system_error_deallocate_message should be called even if 0 is returned - // pre: *_Ptr_str == nullptr const unsigned long _Chars = FormatMessageA(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS, nullptr, _Message_id, _Lang_id, reinterpret_cast(_Ptr_str), 0, nullptr);