Skip to content

Conversation

@oldnewthing
Copy link
Member

The OS version of RoOriginateLanguageException converts empty messages into an error message produced by FormatMessage. Our fallback Win7 version does not have this feature, which causes errors to be produced with no message.

This defect had been present since inception but was exposed by a correctness fix to hstring.c_str() so that it returned an empty string (instead of nullptr) for the null hstring.

Prior to the hstring fix, the implementation of error_info_fallback::GetErrorDetails would happily pass nullptr to SysAllocString, which failed with an invalid parameter. This error was propagated (mistakenly as error_bad_alloc), and that caused hresult_error.message() to fall back to FormatMessage.

With the hstring fix, the implementation of error_info_fallback::GetErrorDetails now passes a non-null empty string, which SysAllocString dutifully allocates and returns.

We fix error_info_fallback by having it autogenerate a message if no message was provided, bringing it into alignment with the RoOriginateLanguageException function it was intended to emulate.

Fixes #623

The OS version of RoOriginateLanguageException converts empty messages
into an error message produced by FormatMessage. Our fallback Win7
version does not have this feature, which causes errors to be produced
with no message.

This defect had been present since inception but was exposed by
a correctness fix to `hstring.c_str()` so that it returned an empty
string (instead of nullptr) for the null hstring.

Prior to the hstring fix, the implementation of
`error_info_fallback::GetErrorDetails` would happily pass `nullptr` to
`SysAllocString`, which failed with an invalid parameter. This error was
propagated (mistakenly as `error_bad_alloc`), and that caused
`hresult_error.message()` to fall back to `FormatMessage`.

With the hstring fix, the implementation of
`error_info_fallback::GetErrorDetails` now passes a non-null empty
string, which `SysAllocString` dutifully allocates and returns.

We fix `error_info_fallback` by having it autogenerate a message if no
message was provided, bringing it into alignment with the
`RoOriginateLanguageException` function it was intended to emulate.
Copy link
Collaborator

@kennykerr kennykerr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@kennykerr kennykerr merged commit fc1a9ab into microsoft:master Jul 30, 2020
@oldnewthing oldnewthing deleted the errorinfo branch July 30, 2020 22:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Empty hresult_error::message() in last C++/WinRT

2 participants