Examples of errors detected by the V534 diagnostic.

V534. It is likely that a wrong variable is being compared inside the 'for' operator. Consider reviewing 'X'.


Source Engine SDK

V534 It is likely that a wrong variable is being compared inside the 'for' operator. Consider reviewing 'i'. Client (HL2) beamdraw.cpp 592


void DrawTeslaSegs(....)
{
  int i;
  ....
  for ( i = 0; i < segments; i++ )
  {
    ....
    for ( int j = 0; i < iBranches; j++ )
    {
      curSeg.m_flWidth *= 0.5;
    }
    ....
  }
  ....
}

Identical errors can be found in some other places:

  • V534 It is likely that a wrong variable is being compared inside the 'for' operator. Consider reviewing 'i'. Client (HL2) beamdraw.cpp 622

Coin3D

V534 It is likely that a wrong variable is being compared inside the 'for' operator. Consider reviewing 'i'. element.cpp 996


cc_xml_elt *
cc_xml_elt_create_x(cc_xml_elt * from, cc_xml_path * path)
{
  ....
  int i;
  for ( i = 0; i < length; i++ ) {
    ....
    int child;
    for (child = 0; i < current->children.getLength(); child++)
    {
  ....
}

Oracle VM Virtual Box

V534 It is likely that a wrong variable is being compared inside the 'for' operator. Consider reviewing 'i'. vboxdispd3d.cpp 4470


static HRESULT APIENTRY vboxWddmDDevCreateResource(....)
{
  ....
  for (UINT i = 0; i < pResource->SurfCount; ++i)
  {
    ....
    if (SUCCEEDED(hr))
    {
      ....
    }
    else
    {
      for (UINT j = 0; i < j; ++j)
      {
        ....
      }
      break;
    }
  }
  ....
}

The error is probably in the "i < j" condition. I think the programmer actually wanted to write j < I.


.NET CoreCLR

V534 It is likely that a wrong variable is being compared inside the 'for' operator. Consider reviewing 'i'. ildasm mdinfo.cpp 1421


void MDInfo::DisplayFields(mdTypeDef inTypeDef,
                           COR_FIELD_OFFSET *rFieldOffset,
                           ULONG cFieldOffset)
 {
  ....
  for (ULONG i = 0; i < count; i++, totalCount++)
  {
    ....
    for (ULONG iLayout = 0; i < cFieldOffset; ++iLayout)  // <=
    {
      if (RidFromToken(rFieldOffset[iLayout].ridOfField) ==
          RidFromToken(fields[i]))
      {
        ....
      }
    }
  }
  ....
}


Do you make errors in the code?

Check your code
with PVS-Studio

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

goto PVS-Studio;