Skip to content

Commit fa51112

Browse files
authored
<system_error>: explicitly pass the system locale ID for system_category messages (#2669)
1 parent b965db4 commit fa51112

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

stl/src/syserror_import_lib.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,15 @@ _NODISCARD size_t __CLRCALL_PURE_OR_STDCALL __std_system_error_allocate_message(
4545
// convert to name of Windows error, return 0 for failure, otherwise return number of chars in buffer
4646
// __std_system_error_deallocate_message should be called even if 0 is returned
4747
// pre: *_Ptr_str == nullptr
48+
DWORD _Lang_id;
49+
const int _Ret = GetLocaleInfoEx(LOCALE_NAME_SYSTEM_DEFAULT, LOCALE_ILANGUAGE | LOCALE_RETURN_NUMBER,
50+
reinterpret_cast<LPWSTR>(&_Lang_id), sizeof(_Lang_id) / sizeof(wchar_t));
51+
if (_Ret == 0) {
52+
_Lang_id = 0;
53+
}
4854
const unsigned long _Chars =
4955
FormatMessageA(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS,
50-
nullptr, _Message_id, 0, reinterpret_cast<char*>(_Ptr_str), 0, nullptr);
56+
nullptr, _Message_id, _Lang_id, reinterpret_cast<char*>(_Ptr_str), 0, nullptr);
5157

5258
return _CSTD __std_get_string_size_without_trailing_whitespace(*_Ptr_str, _Chars);
5359
}

0 commit comments

Comments
 (0)