To get a trial key
fill out the form below
Team License (a basic version)
Enterprise License (extended version)
* By clicking this button you agree to our Privacy Policy statement

Request our prices
New License
License Renewal
--Select currency--
USD
EUR
GBP
RUB
* By clicking this button you agree to our Privacy Policy statement

Free PVS-Studio license for Microsoft MVP specialists
* By clicking this button you agree to our Privacy Policy statement

To get the licence for your open-source project, please fill out this form
* By clicking this button you agree to our Privacy Policy statement

I am interested to try it on the platforms:
* By clicking this button you agree to our Privacy Policy statement

Message submitted.

Your message has been sent. We will email you at


If you haven't received our response, please do the following:
check your Spam/Junk folder and click the "Not Spam" button for our message.
This way, you won't miss messages from our team in the future.

>
>
>
Examples of errors detected by the V545…

Examples of errors detected by the V545 diagnostic

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)


This website uses cookies and other technology to provide you a more personalized experience. By continuing the view of our web-pages you accept the terms of using these files. If you don't want your personal data to be processed, please, leave this site.
Learn More →
Accept