Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

<system_error>: explicitly pass the system locale ID for system_category messages #2669

Merged
merged 3 commits into from
May 1, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion stl/src/syserror_import_lib.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,15 @@ _NODISCARD size_t __CLRCALL_PURE_OR_STDCALL __std_system_error_allocate_message(
// 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<LPWSTR>(&_Lang_id), sizeof(_Lang_id) / sizeof(wchar_t));
if (_Ret == 0) {
_Lang_id = 0;
}
const unsigned long _Chars =
FormatMessageA(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS,
nullptr, _Message_id, 0, reinterpret_cast<char*>(_Ptr_str), 0, nullptr);
nullptr, _Message_id, _Lang_id, reinterpret_cast<char*>(_Ptr_str), 0, nullptr);

return _CSTD __std_get_string_size_without_trailing_whitespace(*_Ptr_str, _Chars);
}
Expand Down