Примеры ошибок, обнаруженных с помощью диагностики V545
V545. Conditional expression of 'if' statement is incorrect for the HRESULT type value 'Foo'. The SUCCEEDED or FAILED macro should be used instead.
VirtualDub
V545 Such conditional expression of 'if' operator is incorrect for the HRESULT type value 'AVIStreamInfoA(pas, & asi, sizeof asi)'. The SUCCEEDED or FAILED macro should be used instead. VirtualDub avireadhandlertunnelw32.cpp 230
#define STDAPI EXTERN_C HRESULT STDAPICALLTYPE
STDAPI AVIStreamInfoA (PAVISTREAM pavi, LPAVISTREAMINFOA psi,
LONG lSize);
#define AVIStreamInfo AVIStreamInfoA
VDPosition AVIReadTunnelStream::TimeToPosition(VDTime timeInUs) {
AVISTREAMINFO asi;
if (AVIStreamInfo(pas, &asi, sizeof asi))
return 0;
return VDRoundToInt64(timeInUs * (double)asi.dwRate /
(double)asi.dwScale * (1.0 / 1000000.0));
}
Similar errors can be found in some other places:
- V545 Such conditional expression of 'if' operator is incorrect for the HRESULT type value 'AVIStreamInfoA(pas, & asi, sizeof asi)'. The SUCCEEDED or FAILED macro should be used instead. VirtualDub avireadhandlertunnelw32.cpp 238
- V545 Such conditional expression of 'if' operator is incorrect for the HRESULT type value 'hr'. The SUCCEEDED or FAILED macro should be used instead. VirtualDub avireadhandlertunnelw32.cpp 335
- V545 Such conditional expression of 'if' operator is incorrect for the HRESULT type value 'err'. The SUCCEEDED or FAILED macro should be used instead. VirtualDub inputfileavi.cpp 440
- And 1 additional diagnostic messages.
Qt
V545 Such conditional expression of 'if' operator is incorrect for the HRESULT type value '(HRESULT) 0L'. The SUCCEEDED or FAILED macro should be used instead. phonon_ds9 qbasefilter.cpp 60
STDMETHODIMP QEnumPins::QueryInterface(const IID &iid,void **out)
{
....
if (S_OK)
AddRef();
return hr;
}
It works on a sheer luck. S_OK is 0, by the way. That is, we don't perform AddRef(). This is what should have been written here: if (hr == S_OK).
LibreOffice
V545 Such conditional expression of 'if' operator is incorrect for the HRESULT type value 'nRC'. The SUCCEEDED or FAILED macro should be used instead. winlayout.cxx 1115
bool UniscribeLayout::LayoutText( ImplLayoutArgs& rArgs )
{
....
HRESULT nRC = ScriptItemize(....);
if( !nRC ) // break loop when everything is correctly itemized
break;
....
}
Apache HTTP Server
V545 Such conditional expression of 'if' operator is incorrect for the HRESULT type value 'SHGetMalloc(& pMalloc)'. The SUCCEEDED or FAILED macro should be used instead. apachemonitor.c 915
#define SHSTDAPI EXTERN_C DECLSPEC_IMPORT HRESULT STDAPICALLTYPE
SHSTDAPI SHGetMalloc(_Outptr_ IMalloc **ppMalloc);
LRESULT CALLBACK ConnectDlgProc(....)
{
....
if (SHGetMalloc(&pMalloc)) { // <=
pMalloc->lpVtbl->Free(pMalloc, il);
pMalloc->lpVtbl->Release(pMalloc);
}
....
}
ANGLE
V545 CWE-253 Such conditional expression of 'if' statement is incorrect for the HRESULT type value '(HRESULT) 0x8007000EL'. The SUCCEEDED or FAILED macro should be used instead. renderer11.cpp 4048
typedef _Return_type_success_(return >= 0) long HRESULT;
#define _HRESULT_TYPEDEF_(_sc) ((HRESULT)_sc)
#define E_OUTOFMEMORY _HRESULT_TYPEDEF_(0x8007000EL)
gl::Error Renderer11::mapResource(....)
{
HRESULT hr = mDeviceContext->Map(resource, subResource,
mapType, mapFlags,
mappedResource);
if (FAILED(hr))
{
....
if (E_OUTOFMEMORY)
{
glError = gl::OutOfMemory() <<
genericFailureMessage <<
gl::FmtHR(hr);
}
return glError;
}
return gl::NoError();
}
Apparently, the correct condition must be as follows: if (hr == E_OUTOFMEMORY)
qdEngine
V545 [CWE-253] Such conditional expression of 'if' statement is incorrect for the HRESULT type value 'graph_builder_->RenderFile(wPath, 0)'. The SUCCEEDED or FAILED macro should be used instead. WinVideo.cpp 139
HRESULT RenderFile(
[in] LPCWSTR lpcwstrFile,
[in] LPCWSTR lpcwstrPlayList
);
class winVideo
{
....
struct IGraphBuilder* graph_builder_;
....
};
bool winVideo::open_file(const char *fname)
{
....
if(graph_builder_ -> RenderFile(wPath,NULL)) { close_file(); return false; }
....
}