Examples of errors detected by the V621 diagnostic.


V621. Consider inspecting the 'for' operator. It's possible that the loop will be executed incorrectly or won't be executed at all.


Geant4 software

V621 Consider inspecting the 'for' operator. It's possible that the loop will be executed incorrectly or won't be executed at all. _G4processes-archive g4qmdcollision.cc 228


void G4QMDCollision::CalKinematicsOfBinaryCollisions(
  G4double dt )
{
  ....
  G4int id = 0;
  ....
  if ( secs )
  {
    ....
    id++;
    ....
  }
  if ( std::abs ( eini - efin ) < fepse*10 )
    ....
  else
  {
    ....
    for ( G4int i0i = 0 ; i0i < id-1 ; i0i++ )
    {
      theSystem->DeleteParticipant( i0i+n0 );
    }
    ....
  }
  ....
}

PuTTY

V621 Consider inspecting the 'for' operator. It's possible that the loop will be executed incorrectly or won't be executed at all. winctrls.c 310


#define snewn(n, type) ((type *)snmalloc((n), sizeof(type)))

void bareradioline(struct ctlpos *cp, int nacross, ...)
{
  va_list ap;
  struct radio *buttons;
  int i, nbuttons;

  va_start(ap, nacross);
  nbuttons = 0;
  while (1) {
    char *btext = va_arg(ap, char *);
    int bid;
    if (!btext)
      break;
    bid = va_arg(ap, int);
  }
  va_end(ap);
  buttons = snewn(nbuttons, struct radio);
  va_start(ap, nacross);
  for (i = 0; i < nbuttons; i++) {
    buttons[i].text = va_arg(ap, char *);
    buttons[i].id = va_arg(ap, int);
  }
  ....
}

When operator for(;; ) begin work, the 'nbuttons' variable still equal zero.

Similar errors can be found in some other places:

  • V621 Consider inspecting the 'for' operator. It's possible that the loop will be executed incorrectly or won't be executed at all. winctrls.c 341

Scilab

V621 Consider inspecting the 'for' operator. It's possible that the loop will be executed incorrectly or won't be executed at all. scicos.c 4432


static void reinitdoit(double *told)
{
  int keve = 0, kiwa = 0;
  ....
  kiwa = 0;
  ....
  for (i = 0; i < kiwa; i++)
  ....
}

Haiku Operation System

V621 Consider inspecting the 'for' operator. It's possible that the loop will be executed incorrectly or won't be executed at all. if_ae.c 1670


#define  AE_IDLE_TIMEOUT 100

static void
ae_stop_rxmac(ae_softc_t *sc)
{
  ....
  /*
   * Wait for IDLE state.
   */
  for (i = 0; i < AE_IDLE_TIMEOUT; i--) {
    val = AE_READ_4(sc, AE_IDLE_REG);
    if ((val & (AE_IDLE_RXMAC | AE_IDLE_DMAWRITE)) == 0)
      break;
    DELAY(100);
  }
  ....
}

Similar errors can be found in some other places:

  • V621 Consider inspecting the 'for' operator. It's possible that the loop will be executed incorrectly or won't be executed at all. if_ae.c 1706

SETI@home

V621 Consider inspecting the 'for' operator. It's possible that the loop will be executed incorrectly or won't be executed at all. schema_master.cpp 9535


std::string hotpix::update_format() const
{
  std::ostringstream rv("");
  for (int i=2;i<2;i++)
    rv << "?,";
  rv << "?";
  return rv.str();
}

Similar errors can be found in some other places:

  • V621 Consider inspecting the 'for' operator. It's possible that the loop will be executed incorrectly or won't be executed at all. schema_master.cpp 11633

Unreal Engine 4

V621 Consider inspecting the 'for' operator. It's possible that the loop will be executed incorrectly or won't be executed at all. quadricmeshreduction.cpp 305


class FQuadricSimplifierMeshReduction : public IMeshReduction
{
public:
  virtual void Reduce(
    FRawMesh& OutReducedMesh,
    float& OutMaxDeviation,
    const FRawMesh& InMesh,
    const FMeshReductionSettings& InSettings
    )
  {
    ....
    uint32 NumIndexes = 0;
    ....
    uint32* Indexes = new uint32[ NumIndexes ];

    for( uint32 i = 0; i < NumIndexes; i++ )
    {
       Indexes[i] = InMesh.WedgeIndices[i];
    }
    ....
  }
  ....
}

FreeSWITCH

V621 Consider inspecting the 'for' operator. It's possible that the loop will be executed incorrectly or won't be executed at all. switch_core.c 3014


SWITCH_DECLARE(int) switch_max_file_desc(void)
{
  int max = 0;                                   // <=

#ifndef WIN32
#if defined(HAVE_GETDTABLESIZE)
  max = getdtablesize();
#else
  max = sysconf(_SC_OPEN_MAX);
#endif
#endif

  return max;

}

SWITCH_DECLARE(void) switch_close_extra_files(....)
{
  int open_max = switch_max_file_desc();
  int i, j;

  for (i = 3; i < open_max; i++) {               // <=
    ....
    close(i);

  skip:

    continue;

  }
}

Mozilla Thunderbird

V621 Consider inspecting the 'for' operator. It's possible that the loop will be executed incorrectly or won't be executed at all. nsmsgdbfolder.cpp 4501


NS_IMETHODIMP
nsMsgDBFolder::GetDisplayRecipients(bool *displayRecipients)
{
  ....
  // There's one FCC folder for sent mail, and one for sent news
  nsIMsgFolder *fccFolders[2];
  int numFccFolders = 0;
  for (int i = 0; i < numFccFolders; i++)
  {
    ....
  }
  ....
}

FreeBSD Kernel

V621 Consider inspecting the 'for' operator. It's possible that the loop will be executed incorrectly or won't be executed at all. if_ae.c 1663


#define  AE_IDLE_TIMEOUT    100

static void
ae_stop_rxmac(ae_softc_t *sc)
{
  int i;
  ....
  /*
   * Wait for IDLE state.
   */
  for (i = 0; i < AE_IDLE_TIMEOUT; i--) {  // <=
    val = AE_READ_4(sc, AE_IDLE_REG);
    if ((val & (AE_IDLE_RXMAC | AE_IDLE_DMAWRITE)) == 0)
      break;
    DELAY(100);
  }
  ....
}

EFL Core Libraries

V621 Consider inspecting the 'for' operator. It's possible that the loop will be executed incorrectly or won't be executed at all. eina_debug.c 405


static void
_opcodes_unregister_all(Eina_Debug_Session *session)
{
  Eina_List *l;
  int i;
  _opcode_reply_info *info = NULL;

  if (!session) return;
  session->cbs_length = 0;
  for (i = 0; i < session->cbs_length; i++)
    eina_list_free(session->cbs[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;