-
Notifications
You must be signed in to change notification settings - Fork 255
Bug: Projected winrt::consume_ methods will nullptr crash if the underlying QueryInterface call fails #1442
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
Changes from all commits
9711e97
0b3279b
83c846b
4a1dd03
8b91053
46f64de
dfbac87
6a71ee1
978e8f5
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -546,6 +546,28 @@ namespace winrt::impl | |
} | ||
return result; | ||
} | ||
|
||
template <typename T> | ||
WINRT_IMPL_NOINLINE void check_cast_result(T* from WINRT_IMPL_SOURCE_LOCATION_ARGS) | ||
dmachaj marked this conversation as resolved.
Show resolved
Hide resolved
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Doesn't need to be a template. Can just take a There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That's fair. If I spin another PR I'll make that change. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Doesn't this have to be There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What sort of ODR problems? The only variance based on compiler options is the SOURCE_LOCATION macro and that already has global ODR guards. The |
||
{ | ||
if (!from) | ||
{ | ||
com_ptr<impl::IRestrictedErrorInfo> restrictedError; | ||
if (WINRT_IMPL_GetRestrictedErrorInfo(restrictedError.put_void()) == 0) | ||
{ | ||
WINRT_IMPL_SetRestrictedErrorInfo(restrictedError.get()); | ||
|
||
int32_t code; | ||
impl::bstr_handle description; | ||
impl::bstr_handle restrictedDescription; | ||
impl::bstr_handle capabilitySid; | ||
if (restrictedError->GetErrorDetails(description.put(), &code, restrictedDescription.put(), capabilitySid.put()) == 0) | ||
{ | ||
throw hresult_error(code, take_ownership_from_abi WINRT_IMPL_SOURCE_LOCATION_FORWARD); | ||
} | ||
} | ||
} | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm wondering if code gen would be better as WINRT_IMPL_NOINLINE [[noreturn]] void throw_failed_cast(hresult code WINRT_IMPL_SOURCE_LOCATION_ARGS)
{
throw hresult_error(code, take_ownership_from_abi WINRT_IMPL_SOURCE_LOCATION_FORWARD);
}
inline void check_cast_result(hresult code WINRT_IMPL_SOURCE_LOCATION_ARGS)
{
if (code < 0) throw_failed_cast(code WINRT_IMPL_SOURCE_LOCATION_FORWARD);
} where we have a new try_as_reason that returns both a pointer and an hresult. void* result{};
hresult code = ptr->QueryInterface(guid_of<To>(), &result);
return { wrap_as_result<To>(result), code }; |
||
} | ||
|
||
#undef WINRT_IMPL_RETURNADDRESS |
Uh oh!
There was an error while loading. Please reload this page.