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

** This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.
Request our prices
New License
License Renewal
--Select currency--
USD
EUR
GBP
RUB
* By clicking this button you agree to our Privacy Policy statement

** This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.
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 V654…

Examples of errors detected by the V654 diagnostic

April 5, 2021

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--){
  ....
}

Similar 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;
  }
}

EFL Core Libraries

V654 The condition of loop is always false. evas_font_query.c 376


EAPI void
evas_common_font_query_size(....)
{
  ....
  size_t cluster = 0;
  size_t cur_cluster = 0;
  ....
  do
  {
    cur_cluster = cluster + 1;

    glyph--;
    if (cur_w > ret_w)
    {
      ret_w = cur_w;
    }
  }
  while ((glyph > first_glyph) && (cur_cluster == cluster));
  ....
}

Ardour

V654 The condition 'tries < 8' of loop is always true. session_transport.cc 68


void
Session::add_post_transport_work (PostTransportWork ptw)
{
  PostTransportWork oldval;
  PostTransportWork newval;
  int tries = 0;

  while (tries < 8) {
    oldval = (PostTransportWork) g_atomic_int_get (....);
    newval = PostTransportWork (oldval | ptw);
    if (g_atomic_int_compare_and_exchange (....)) {
      /* success */
      return;
    }
  }

  error << "Could not set post transport work! ...." << endmsg;
}

RT-Thread

V654 CWE-834 The condition 'i <= 255' of loop is always true. drv_ft5x06.c 160


static int ft5x06_dump(void)
{
  uint8_t i;
  uint8_t reg_value;

  DEBUG_PRINTF("[FTS] Touch Chip\r\n");

  for (i = 0; i <= 255; i++)
  {
    _ft5x06_read(i, ®_value, 1);

    if (i % 8 == 7)
      DEBUG_PRINTF("0x%02X = 0x%02X\r\n", i, reg_value);
    else
      DEBUG_PRINTF("0x%02X = 0x%02X ", i, reg_value);
  }
  DEBUG_PRINTF("\n");

  return 0;
}

Android

V654 CWE-834 The condition 'gate_id <= 0xFF' of loop is always true. nfa_hci_utils.cc 248


#define NFA_HCI_LAST_PROP_GATE 0xFF

tNFA_HCI_DYN_GATE* nfa_hciu_alloc_gate(uint8_t gate_id,
                                       tNFA_HANDLE app_handle) {
  ....
  for (gate_id = NFA_HCI_FIRST_HOST_SPECIFIC_GENERIC_GATE;
       gate_id <= NFA_HCI_LAST_PROP_GATE; gate_id++) {
    if (gate_id == NFA_HCI_CONNECTIVITY_GATE) gate_id++;
    if (nfa_hciu_find_gate_by_gid(gate_id) == NULL) break;
  }

  if (gate_id > NFA_HCI_LAST_PROP_GATE) {
    LOG(ERROR) << StringPrintf(
        "nfa_hci_alloc_gate - no free Gate ID: %u  "
        "App Handle: 0x%04x", gate_id, app_handle);
    return (NULL);
  }
  ....
}

Android

V654 CWE-834 The condition '++ retries' of loop is always true. SimpleDecodingSource.cpp 226


status_t SimpleDecodingSource::doRead(....) {
  ....
  for (int retries = 0; ++retries; ) {
  ....
}

Stellarium

V654 The condition 'start_of_directory == - 1' of loop is always true. qzip.cpp 617


void QZipReaderPrivate::scanFiles()
{
  ....
  // find EndOfDirectory header
  int i = 0;
  int start_of_directory = -1;
  EndOfDirectory eod;
  while (start_of_directory == -1) {
    const int pos = device->size()
      - int(sizeof(EndOfDirectory)) - i;
    if (pos < 0 || i > 65535) {
      qWarning() << "QZip: EndOfDirectory not found";
      return;
    }

    device->seek(pos);
    device->read((char *)&eod, sizeof(EndOfDirectory));
    if (readUInt(eod.signature) == 0x06054b50)
      break;
    ++i;
  }
  ....
}

Haiku Operation System

V654 The condition 'specificSequence != sequence' of loop is always false. pthread_key.cpp 55


static void*
get_key_value(pthread_thread* thread, uint32 key, int32 sequence)
{
  pthread_key_data& keyData = thread->specific[key];
  int32 specificSequence;
  void* value;

  do {
    specificSequence = keyData.sequence;
    if (specificSequence != sequence)
      return NULL;

    value = keyData.value;
  } while (specificSequence != sequence);

  keyData.value = NULL;

  return value;
}

Doom 1

V654 [CWE-834] The condition 'player->pendingweapon == wp_nochange' of loop is always false. p_pspr.c 232


boolean P_CheckAmmo (player_t* player)
{
  ....
  do {
    if (....)
    {
      player->pendingweapon = wp_plasma;
    }
    else .... if (....)
    {
      player->pendingweapon = wp_bfg;
    }
    else
    {
      player->pendingweapon = wp_fist;
    }
  } while (player->pendingweapon == wp_nochange);
  ....
}

Newton Game Dynamics

V654 The condition 'i < count' of loop is always false. MultiBodyCar.cpp 942


void MultibodyBodyCar(DemoEntityManager* const scene)
{
  ....
  int count = 10;
  count = 0;
  for (int i = 0; i < count; i++)
  {
    for (int j = 0; j < count; j++)
    {
      dMatrix offset(location);
      offset.m_posit += dVector (j * 5.0f + 4.0f, 0.0f, i * 5.0f, 0.0f);
      //manager->CreateSportCar(offset, viperModel.GetData());
      manager->CreateOffRoadCar(offset, monsterTruck.GetData());
    }
  }
  ....
}

Free Heroes of Might and Magic II

V654 The condition 'i < originalPalette.size()' of loop is always false. battle_interface.cpp 3689


void Battle::Interface::RedrawActionBloodLustSpell( Unit & target )
{
  std::vector<std::vector<uint8_t> > originalPalette;
  if ( target.Modes( SP_STONE ) )
  {
    originalPalette.push_back( PAL::GetPalette( PAL::GRAY ) );
  }
  else if ( target.Modes( CAP_MIRRORIMAGE ) )
  {
    originalPalette.push_back( PAL::GetPalette( PAL::MIRROR_IMAGE ) );
  }
  if ( !originalPalette.empty() )
  {
    for ( size_t i = 1; i < originalPalette.size(); ++i )
    {
      originalPalette[0] = PAL::CombinePalettes( originalPalette[0],
                                                 originalPalette[i] );
    }
    fheroes2::ApplyPalette( unitSprite, originalPalette[0] );
  }
  ....
}

Snort

V654 The condition '!done' of loop is always true. log.c 207


void PrintNetData(....)
{
  int done;           /* flag */
  ....

  /* initialization */
  done = 0;
  ....

  /* loop thru the whole buffer */
  while(!done)
    {
      ....
    }
  ....
}

Popular related articles
PVS-Studio for Java

Date: 01.17.2019

Author: Andrey Karpov

In the seventh version of the PVS-Studio static analyzer, we added support of the Java language. It's time for a brief story of how we've started making support of the Java language, how far we've co…
PVS-Studio ROI

Date: 01.30.2019

Author: Andrey Karpov

Occasionally, we're asked a question, what monetary value the company will receive from using PVS-Studio. We decided to draw up a response in the form of an article and provide tables, which will sho…
The way static analyzers fight against false positives, and why they do it

Date: 03.20.2017

Author: Andrey Karpov

In my previous article I wrote that I don't like the approach of evaluating the efficiency of static analyzers with the help of synthetic tests. In that article, I give the example of a code fragment…
Technologies used in the PVS-Studio code analyzer for finding bugs and potential vulnerabilities

Date: 11.21.2018

Author: Andrey Karpov

A brief description of technologies used in the PVS-Studio tool, which let us effectively detect a large number of error patterns and potential vulnerabilities. The article describes the implementati…
Characteristics of PVS-Studio Analyzer by the Example of EFL Core Libraries, 10-15% of False Positives

Date: 07.31.2017

Author: Andrey Karpov

After I wrote quite a big article about the analysis of the Tizen OS code, I received a large number of questions concerning the percentage of false positives and the density of errors (how many erro…
Free PVS-Studio for those who develops open source projects

Date: 12.22.2018

Author: Andrey Karpov

On the New 2019 year's eve, a PVS-Studio team decided to make a nice gift for all contributors of open-source projects hosted on GitHub, GitLab or Bitbucket. They are given free usage of PVS-Studio s…
The Ultimate Question of Programming, Refactoring, and Everything

Date: 04.14.2016

Author: Andrey Karpov

Yes, you've guessed correctly - the answer is "42". In this article you will find 42 recommendations about coding in C++ that can help a programmer avoid a lot of errors, save time and effort. The au…
How PVS-Studio Proved to Be More Attentive Than Three and a Half Programmers

Date: 10.22.2018

Author: Andrey Karpov

Just like other static analyzers, PVS-Studio often produces false positives. What you are about to read is a short story where I'll tell you how PVS-Studio proved, just one more time, to be more atte…
The Evil within the Comparison Functions

Date: 05.19.2017

Author: Andrey Karpov

Perhaps, readers remember my article titled "Last line effect". It describes a pattern I've once noticed: in most cases programmers make an error in the last line of similar text blocks. Now I want t…
The Last Line Effect

Date: 05.31.2014

Author: Andrey Karpov

I have studied many errors caused by the use of the Copy-Paste method, and can assure you that programmers most often tend to make mistakes in the last fragment of a homogeneous code block. I have ne…

Comments (0)

Next comments

This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.
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