Examples of errors detected by the V543 diagnostic.


V543. It is odd that value 'X' is assigned to the variable 'Y' of HRESULT type.


WinMerge

V543 It is odd that value '-1' is assigned to the variable 'h' of HRESULT type. Merge plugins.cpp 992


static HRESULT safeInvokeA(LPDISPATCH pi, VARIANT *ret,
                           DISPID id, LPCCH op, ...)
{
  HRESULT h;
  ...
  // set h to FAILED
  h = -1;
  ...
}

Similar errors can be found in some other places:

  • V543 It is odd that value '-1' is assigned to the variable 'h' of HRESULT type. Merge plugins.cpp 1033

Oracle VM Virtual Box

V543 It is odd that value 'true' is assigned to the variable 'mRemoveSavedState' of HRESULT type. machineimpl.cpp 12247


class ATL_NO_VTABLE SessionMachine : public Machine
{
  ....
  HRESULT mRemoveSavedState;
  ....
}

HRESULT SessionMachine::init(Machine *aMachine)
{
  ....
  /* default is to delete saved state on
   * Saved -> PoweredOff transition */
  mRemoveSavedState = true;
  ....
}

Unreal Engine 4

V543 It is odd that value '-1' is assigned to the variable 'Result' of HRESULT type. unrealaudiodevicewasapi.cpp 568


#define S_OK     ((HRESULT)0L)
#define S_FALSE  ((HRESULT)1L)

bool FUnrealAudioWasapi::OpenDevice(uint32 DeviceIndex,
                                    EStreamType::Type StreamType)
{
  check(WasapiInfo.DeviceEnumerator);

  IMMDevice* Device = nullptr;
  IMMDeviceCollection* DeviceList = nullptr;
  WAVEFORMATEX* DeviceFormat = nullptr;
  FDeviceInfo DeviceInfo;
  HRESULT Result = S_OK;                                   // <=
  ....
  if (!GetDeviceInfo(DataFlow, DeviceIndex, DeviceInfo))
  {
    Result = -1;                                           // <=
    goto Cleanup;
  }
  ....
}


Do you make errors in the code?

Check your code
with PVS-Studio

Static code analysis
for C, C++ and C#

goto PVS-Studio;