Examples of errors detected by the V654 diagnostic

V654. The condition of loop is always true/false.


Apache HTTP Server

V654 The condition 'retry < 2' of loop is always true. mod_proxy_wstunnel mod_proxy_wstunnel.c 436


static int proxy_wstunnel_handler(....)
{
  int retry;
  ....
  retry = 0;
  while (retry < 2) {
    char *locurl = url;
    ....
    // Variable 'retry' is not used
    ....
  }
  ....
}

WebRTC

V654 The condition 'loopCnt < 5' of loop is always true. cpr_win_socket.c 746


#define TCP_PORT_RETRY_CNT  5

cpr_socket_t
cprSecSocConnect (char *host,
                  int     port,
                  int     ipMode,
                  boolean mode,
                  uint32_t tos,
                  uint16_t *localPort)
{
  ....
  uint16_t loopCnt  = 0;
  ....
  while (loopCnt < TCP_PORT_RETRY_CNT) {
    ....
    .... // loopCnt not changed
    ....
  }
  ....
}

Oracle VM Virtual Box

V654 The condition of loop is always true. suphardenedverifyprocess-win.cpp 1732


DECLHIDDEN(int) supHardNtLdrCacheOpen(const char *pszName, ....)
{
  ....
  uint32_t i = 0;
  while (i < RT_ELEMENTS(g_apszSupNtVpAllowedDlls))
    if (!strcmp(pszName, g_apszSupNtVpAllowedDlls[i]))
      break;
  ....
}

What is dangerous about this loop is that the counter value doesn't change, so if the very first array item doesn't coincide with 'pszName', we'll get an infinite loop.


K Desktop Environment

V654 The condition 'state != 1' of loop is always true. passwd.cpp 255


int PasswdProcess::ConversePasswd(....)
{
  ....
  state = 0;
  while (state != 1)
  {
    line = readLine();
    if (line.isNull())
    {
      // No more input... OK
      return 0;
    }
    if (isPrompt(line, "password"))
    {
      // Uh oh, another prompt. Not good!
      kill(m_Pid, SIGKILL);
      waitForChild();
      return PasswordNotGood;
    }
    m_Error += line + '\n'; // Collect error message
  }
  ....
}

Miranda NG

V654 The condition '5' of loop is always true. Xfire main.cpp 1110


extern "C" __declspec(dllexport) int  Load(void)
{
  ....
  for (i = MAX_PATH; 5; i--){
  ....
}

Identical errors can be found in some other places:

  • V654 The condition '5' of loop is always true. Xfire variables.cpp 194

Linux Kernel

V654 The condition 'i < 10' of loop is always true. qla3xxx.c 149


static int ql_wait_for_drvr_lock(struct ql3_adapter *qdev)
{
  int i = 0;

  while (i < 10) {
    if (i)
      ssleep(1);

    if (ql_sem_lock(qdev,
        QL_DRVR_SEM_MASK,
        (QL_RESOURCE_BITS_BASE_CODE | (qdev->mac_index)
         * 2) << 1)) {
      netdev_printk(KERN_DEBUG, qdev->ndev,
              "driver lock acquired\n");
      return 1;
    }
  }

  netdev_err(qdev->ndev,
             "Timed out waiting for driver lock...\n");
  return 0;
}

Unreal Engine 4

V654 The condition '!bFoundName' of loop is always true. edgraphutilities.cpp 244


void FEdGraphUtilities::RenameGraphCloseToName(....)
{
  bool bFoundName = false;

  FString NewName = BaseName;

  int32 NameIndex = StartIndex;
  while (!bFoundName)
  {
    if (Graph->Rename(*NewName, Graph->GetOuter(), REN_Test))
    {
      UBlueprint* BP = FBlueprintEditorUtils....;
      Graph->Rename(*NewName, Graph->GetOuter(), ....);
      return;
    }

    NewName = FString::Printf(TEXT("%s_%d"),*BaseName,NameIndex);
    ++NameIndex;
  }
}

Git

V654 The condition of loop is always false. sha1_file.c 693


void release_pack_memory(size_t need)
{
  size_t cur = pack_mapped;
  while (need >= (cur - pack_mapped) && unuse_one_window(NULL))
    ; /* nothing */
}


Do you make errors in the code?

Check your code
with PVS-Studio

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

goto PVS-Studio;