Skip to content

Commit

Permalink
C26474, don't use static_cast when an implicit cast is acceptable.
Browse files Browse the repository at this point in the history
  • Loading branch information
miniksa committed Sep 3, 2019
1 parent 30e8e7f commit cdfbf8f
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 47 deletions.
41 changes: 16 additions & 25 deletions src/types/ScreenInfoUiaProviderBase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ ScreenInfoUiaProviderBase::~ScreenInfoUiaProviderBase()
}
CATCH_RETURN();

IRawElementProviderSimple* pProvider = static_cast<IRawElementProviderSimple*>(this);
IRawElementProviderSimple* pProvider = this;
hr = UiaRaiseAutomationEvent(pProvider, id);
_signalFiringMapping[id] = false;

Expand Down Expand Up @@ -102,29 +102,20 @@ IFACEMETHODIMP ScreenInfoUiaProviderBase::QueryInterface(_In_ REFIID riid,

// TODO GitHub #1914: Re-attach Tracing to UIA Tree
//Tracing::s_TraceUia(this, ApiCall::QueryInterface, nullptr);
if (riid == __uuidof(IUnknown))
if (riid == __uuidof(IUnknown) ||
riid == __uuidof(IRawElementProviderSimple) ||
riid == __uuidof(IRawElementProviderFragment) ||
riid == __uuidof(ITextProvider))
{
*ppInterface = static_cast<IRawElementProviderSimple*>(this);
}
else if (riid == __uuidof(IRawElementProviderSimple))
{
*ppInterface = static_cast<IRawElementProviderSimple*>(this);
}
else if (riid == __uuidof(IRawElementProviderFragment))
{
*ppInterface = static_cast<IRawElementProviderFragment*>(this);
}
else if (riid == __uuidof(ITextProvider))
{
*ppInterface = static_cast<ITextProvider*>(this);
*ppInterface = this;
}
else
{
*ppInterface = nullptr;
return E_NOINTERFACE;
}

(static_cast<IUnknown*>(*ppInterface))->AddRef();
AddRef();

return S_OK;
}
Expand Down Expand Up @@ -161,7 +152,7 @@ IFACEMETHODIMP ScreenInfoUiaProviderBase::GetPatternProvider(_In_ PATTERNID patt

if (patternId == UIA_TextPatternId)
{
hr = this->QueryInterface(__uuidof(ITextProvider), reinterpret_cast<void**>(ppInterface));
hr = this->QueryInterface(IID_PPV_ARGS(ppInterface));
if (FAILED(hr))
{
*ppInterface = nullptr;
Expand Down Expand Up @@ -354,7 +345,7 @@ IFACEMETHODIMP ScreenInfoUiaProviderBase::GetSelection(_Outptr_result_maybenull_
range = nullptr;
hr = wil::ResultFromCaughtException();
}
(static_cast<IUnknown*>(pProvider))->Release();
pProvider->Release();
if (range == nullptr)
{
SafeArrayDestroy(*ppRetVal);
Expand All @@ -363,7 +354,7 @@ IFACEMETHODIMP ScreenInfoUiaProviderBase::GetSelection(_Outptr_result_maybenull_
}

LONG currentIndex = 0;
hr = SafeArrayPutElement(*ppRetVal, &currentIndex, reinterpret_cast<void*>(range));
hr = SafeArrayPutElement(*ppRetVal, &currentIndex, range);
if (FAILED(hr))
{
SafeArrayDestroy(*ppRetVal);
Expand Down Expand Up @@ -403,7 +394,7 @@ IFACEMETHODIMP ScreenInfoUiaProviderBase::GetSelection(_Outptr_result_maybenull_
// fill the safe array
for (LONG i = 0; i < gsl::narrow<LONG>(ranges.size()); ++i)
{
hr = SafeArrayPutElement(*ppRetVal, &i, reinterpret_cast<void*>(ranges.at(i)));
hr = SafeArrayPutElement(*ppRetVal, &i, ranges.at(i));
if (FAILED(hr))
{
SafeArrayDestroy(*ppRetVal);
Expand Down Expand Up @@ -490,7 +481,7 @@ IFACEMETHODIMP ScreenInfoUiaProviderBase::GetVisibleRanges(_Outptr_result_mayben
range = nullptr;
hr = wil::ResultFromCaughtException();
}
(static_cast<IUnknown*>(pProvider))->Release();
pProvider->Release();

if (range == nullptr)
{
Expand All @@ -500,7 +491,7 @@ IFACEMETHODIMP ScreenInfoUiaProviderBase::GetVisibleRanges(_Outptr_result_mayben
}

LONG currentIndex = gsl::narrow<LONG>(i);
hr = SafeArrayPutElement(*ppRetVal, &currentIndex, reinterpret_cast<void*>(range));
hr = SafeArrayPutElement(*ppRetVal, &currentIndex, range);
if (FAILED(hr))
{
SafeArrayDestroy(*ppRetVal);
Expand Down Expand Up @@ -534,7 +525,7 @@ IFACEMETHODIMP ScreenInfoUiaProviderBase::RangeFromChild(_In_ IRawElementProvide
*ppRetVal = nullptr;
hr = wil::ResultFromCaughtException();
}
(static_cast<IUnknown*>(pProvider))->Release();
pProvider->Release();

return hr;
}
Expand Down Expand Up @@ -563,7 +554,7 @@ IFACEMETHODIMP ScreenInfoUiaProviderBase::RangeFromPoint(_In_ UiaPoint point,
*ppRetVal = nullptr;
hr = wil::ResultFromCaughtException();
}
(static_cast<IUnknown*>(pProvider))->Release();
pProvider->Release();

return hr;
}
Expand All @@ -590,7 +581,7 @@ IFACEMETHODIMP ScreenInfoUiaProviderBase::get_DocumentRange(_COM_Outptr_result_m
*ppRetVal = nullptr;
hr = wil::ResultFromCaughtException();
}
(static_cast<IUnknown*>(pProvider))->Release();
pProvider->Release();

if (*ppRetVal)
{
Expand Down
11 changes: 4 additions & 7 deletions src/types/UiaTextRangeBase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -266,21 +266,18 @@ IFACEMETHODIMP UiaTextRangeBase::QueryInterface(_In_ REFIID riid, _COM_Outptr_re
// TODO GitHub #1914: Re-attach Tracing to UIA Tree
//Tracing::s_TraceUia(this, ApiCall::QueryInterface, nullptr);

if (riid == __uuidof(IUnknown))
if (riid == __uuidof(IUnknown) ||
riid == __uuidof(ITextRangeProvider))
{
*ppInterface = static_cast<ITextRangeProvider*>(this);
}
else if (riid == __uuidof(ITextRangeProvider))
{
*ppInterface = static_cast<ITextRangeProvider*>(this);
*ppInterface = this;
}
else
{
*ppInterface = nullptr;
return E_NOINTERFACE;
}

(static_cast<IUnknown*>(*ppInterface))->AddRef();
AddRef();
return S_OK;
}

Expand Down
21 changes: 6 additions & 15 deletions src/types/WindowUiaProviderBase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,29 +37,20 @@ WindowUiaProviderBase::Release()
IFACEMETHODIMP WindowUiaProviderBase::QueryInterface(_In_ REFIID riid, _COM_Outptr_result_maybenull_ void** ppInterface)
{
RETURN_HR_IF_NULL(E_INVALIDARG, ppInterface);
if (riid == __uuidof(IUnknown))
if (riid == __uuidof(IUnknown) ||
riid == __uuidof(IRawElementProviderSimple) ||
riid == __uuidof(IRawElementProviderFragment) ||
riid == __uuidof(IRawElementProviderFragmentRoot))
{
*ppInterface = static_cast<IRawElementProviderSimple*>(this);
}
else if (riid == __uuidof(IRawElementProviderSimple))
{
*ppInterface = static_cast<IRawElementProviderSimple*>(this);
}
else if (riid == __uuidof(IRawElementProviderFragment))
{
*ppInterface = static_cast<IRawElementProviderFragment*>(this);
}
else if (riid == __uuidof(IRawElementProviderFragmentRoot))
{
*ppInterface = static_cast<IRawElementProviderFragmentRoot*>(this);
*ppInterface = this;
}
else
{
*ppInterface = nullptr;
return E_NOINTERFACE;
}

(static_cast<IUnknown*>(*ppInterface))->AddRef();
AddRef();

return S_OK;
}
Expand Down

0 comments on commit cdfbf8f

Please sign in to comment.