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.
To get the licence for your open-source project, please fill out this form
* 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.
To get the licence for your open-source project, please fill out this form
* 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.
I am interested to try it on the platforms:
* 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 V503…

Examples of errors detected by the V503 diagnostic

Apr 05 2021

V503. This is a nonsensical comparison: pointer < 0.


Xpdf

V503 This is a nonsensical comparison: pointer < 0. pdf2swf q.c 804


char* stringarray_at(stringarray_t*sa, int pos)
{
  stringarray_internal_t*s =
    (stringarray_internal_t*)sa->internal;
  char *p;
  if (pos<0 || pos>=s->num)
    return 0;

  p = *(char**)&s->pos.buffer[pos*sizeof(char*)];

  if(p<0)  // <=
    return 0;

  return p;
}

IPP Samples

V503 This is a nonsensical comparison: pointer < 0. ipprsample ippr_sample.cpp 501


void lNormalizeVector_32f_P3IM(Ipp32f *vec[3],
                               Ipp32s* mask, Ipp32s len)
{
  Ipp32s  i;
  Ipp32f  norm;

  for(i=0; i<len; i++) {
    if(mask<0) continue;
    norm = 1.0f/sqrt(vec[0][i]*vec[0][i]+
                     vec[1][i]*vec[1][i]+
                     vec[2][i]*vec[2][i]);
    vec[0][i] *= norm; vec[1][i] *= norm; vec[2][i] *= norm;
  }
}

This is what should have been written here: if(mask[i]<0) continue;


Chromium

V503 This is a nonsensical comparison: pointer < 0. browser profile_impl.cc 169


void GetCacheParameters(ContextType type, FilePath* cache_path,
                        int* max_size) {
  ....
  *max_size = 0;
  if (!base::StringToInt(value, max_size)) {
    *max_size = 0;
  } else if (max_size < 0) {
    *max_size = 0;
  }
  ....
}

Chromium

V503 This is a nonsensical comparison: pointer < 0. platform_file_win.cc 124


typedef void *HANDLE;

#if defined(OS_WIN)
  typedef HANDLE PlatformFile;
#elif defined(OS_POSIX)
  typedef int PlatformFile;
#endif

int64 SeekPlatformFile(PlatformFile file,
                       PlatformFileWhence whence,
                       int64 offset) {
  base::ThreadRestrictions::AssertIOAllowed();
  if (file < 0 || offset < 0)
    return -1;

  LARGE_INTEGER distance, res;
  distance.QuadPart = offset;
  DWORD move_method = static_cast<DWORD>(whence);
  if (!SetFilePointerEx(file, distance, &res, move_method))
    return -1;
  return res.QuadPart;
}

Scilab

V503 This is a nonsensical comparison: pointer < 0. scicos.c 5826


int write_xml_states(....)
{
  ....
  FILE *fd = NULL;
  ....
  wcfopen(fd, (char*)xmlfile, "wb");
  if (fd < 0)
  {
    sciprint(_("Error: cannot write to  '%s'  \n"), xmlfile);
    ....
}

OGDF

V503 This is a nonsensical comparison: pointer <= 0. sugiyama.cpp 571


int Hierarchy::calculateCrossingsPlaneSweep(int i)
{
  const Level *pLevel[2];
  pLevel[0] = m_pLevel[i]; pLevel[1] = m_pLevel[i+1];
  if (pLevel[0]->high() <= 0 || pLevel[1] <= 0) return 0;
  ....
}

Asterisk

V503 This is a nonsensical comparison: pointer < 0. parking_manager.c 520


static int manager_park(....)
{
  ....
  const char *timeout = astman_get_header(m, "Timeout");
  ....
  int timeout_override = -1;
  ....
  if (sscanf(timeout, "%30d", &timeout_override) != 1 ||
    timeout < 0) {                                          // <=
      astman_send_error(s, m, "Invalid Timeout value.");
      return 0;
  }
}

.NET CoreCLR

V503 This is a nonsensical comparison: pointer >= 0. cee_wks gc.cpp 21707


void gc_heap::make_free_list_in_brick (BYTE* tree,
                                       make_free_args* args)
{
  assert ((tree >= 0));
  ....
}

Similar errors can be found in some other places:

  • V503 This is a nonsensical comparison: pointer >= 0. cee_wks gc.cpp 23204
  • V503 This is a nonsensical comparison: pointer >= 0. cee_wks gc.cpp 27683

Haiku Operation System

V503 This is a nonsensical comparison: pointer <= 0. Header.cpp 900


extern
char *strstr(const char *string, const char *searchString);

void
TTextControl::MessageReceived(BMessage *msg)
{
  ....
  while (node.GetNextAttrName(buffer) == B_OK) {
    if (strstr(buffer, "email") <= 0)
      continue;
  ....
}

GINV

V503 This is a nonsensical comparison: pointer < 0. imonom.cpp 477


class IMonom {
  ....
  const IVariables* depend();
}

std::ostream& operator<<(std::ostream& out, const IMonom& a) {
  switch(a.monomInterface()->systemType()->type()) {
  ....
  case ISystemType::DifferentialEquation: {
    IASSERT(a.depend() != NULL);
    if (a.degree() == 0)
      if (a.depend() < 0)
      {
      }
      ....
    }
  }
}

Similar errors can be found in some other places:

  • V503 This is a nonsensical comparison: pointer < 0. imonom.cpp 482
  • V503 This is a nonsensical comparison: pointer < 0. imonom.cpp 504
  • V503 This is a nonsensical comparison: pointer < 0. imonom.cpp 509
  • And 3 additional diagnostic messages.

FreeBSD Kernel

V503 This is a nonsensical comparison: pointer >= 0. geom_vinum_plex.c 173


static int
gv_plex_offset(...., int *sdno, int growing)
{
  ....
  *sdno = stripeno % sdcount;
  ....
  KASSERT(sdno >= 0, ("gv_plex_offset: sdno < 0"));
  ....
}

Similar errors can be found in some other places:

  • V503 This is a nonsensical comparison: pointer >= 0. geom_vinum_raid5.c 602
  • V503 This is a nonsensical comparison: pointer >= 0. geom_vinum_raid5.c 610

OpenToonz

V503 This is a nonsensical comparison: pointer < 0. styleselection.cpp 104


bool pasteStylesDataWithoutUndo(....)
{
  ....
  if (palette->getStylePage(styleId) < 0) { // <=
    // styleId non e' utilizzato: uso quello
    // (cut/paste utilizzato per spostare stili)
    palette->setStyle(styleId, style);
  } else {
    // styleId e' gia' utilizzato. ne devo prendere un altro
    styleId = palette->getFirstUnpagedStyle();
    if (styleId >= 0)
      palette->setStyle(styleId, style);
    else
      styleId = palette->addStyle(style);
  }
  ....
}

The getStylePage() function returns a pointer to some page: TPalette::Page*.


Far2l

V503 This is a nonsensical comparison: pointer <= 0. fstd_exSCPY.cpp 8


char *WINAPI StrCpy(char *dest, LPCSTR src, int dest_sz)
{
  if(dest <= 0)
    return NULL;
  ....
}

Tizen

V503 This is a nonsensical comparison: pointer < 0. apps_view_circle_indicator.c 193


static void __page_focus_changed_cb(void *data)
{
  int i = 0;
  int *focus_unit = (int *)data;
  if (focus_unit == NULL || focus_unit < 0) {
    _E("focus page is wrong");
    return ;
  }
  ....
}

This is what should have been written here: if (focus_unit == NULL || *focus_unit < 0)


Tizen

V503 This is a nonsensical comparison: pointer < 0. apps_view_circle_indicator.c 219


static void __page_count_changed_cb(void *data)
{
  int i = 0;
  int *page_cnt = (int *)data;
  if (page_cnt == NULL || page_cnt < 0) {
    _E("page count is wrong");
    return ;
  }
  ....
}

This is what should have been written here: if (page_cnt == NULL || *page_cnt < 0)


Popular related articles
Appreciate Static Code Analysis!

Date: Oct 16 2017

Author: Andrey Karpov

I am really astonished by the capabilities of static code analysis even though I am one of the developers of PVS-Studio analyzer myself. The tool surprised me the other day as it turned out to be sma…
How PVS-Studio Proved to Be More Attentive Than Three and a Half Programmers

Date: Oct 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…
Free PVS-Studio for those who develops open source projects

Date: Dec 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: Apr 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…
PVS-Studio ROI

Date: Jan 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 Last Line Effect

Date: May 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…
Characteristics of PVS-Studio Analyzer by the Example of EFL Core Libraries, 10-15% of False Positives

Date: Jul 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…
The Evil within the Comparison Functions

Date: May 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 way static analyzers fight against false positives, and why they do it

Date: Mar 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: Nov 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…

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