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 V511…

Examples of errors detected by the V511 diagnostic

Apr 05 2021

V511. The sizeof() operator returns size of the pointer, and not of the array, in given expression.


Shareaza

V511 The sizeof() operator returns size of the pointer, and not of the array, in 'sizeof ( arrChar )' expression. BugTrap encoding.cpp 477


#define countof(array) (sizeof(array) / sizeof((array)[0]))

size_t AnsiDecodeChar(const BYTE* pBytes,
  size_t nNumBytes, TCHAR arrChar[2],
  size_t& nCharSize)
{
  ....
    nCharSize = MultiByteToWideChar(CP_ACP, 0,
      (const CHAR*)pBytes, nNumBytesInChar,
      arrChar, countof(arrChar));
  ....
}

The B object is simply a pointer. Value 2 in the square brackets indicates to the programmer that he is working with an array of 2 items. But it is not an array of items which is passed into the function - it is only the pointer. So, the sizeof(arrChar) expression will return value 4 or 8 (the size of the pointer in a 32-bit/64-bit system).


Wolfenstein 3D

V511 The sizeof() operator returns size of the pointer, and not of the array, in 'sizeof (src)' expression. Splines math_matrix.h 94


ID_INLINE mat3_t::mat3_t( float src[ 3 ][ 3 ] ) {
  memcpy( mat, src, sizeof( src ) );
}

The 'src' object is simply a pointer. Value 3x3 in the square brackets indicates to the programmer that he is working with an array of 3x3 items. But it is not an array of items which is passed into the function - it is only the pointer. So, the sizeof(src) expression will return value 4 or 8 (the size of the pointer in a 32-bit/64-bit system).


Wolfenstein 3D

V511 The sizeof() operator returns size of the pointer, and not of the array, in 'sizeof (result)' expression. cgame bg_animation.c 807


void BG_ParseConditionBits(
  char **text_pp, animStringItem_t *stringTable,
  int condIndex, int result[2] )
{
  ....
  memset( result, 0, sizeof( result ) );
  ....
}

The 'result' object is simply a pointer. Value 2 in the square brackets indicates to the programmer that he is working with an array of 2 items. But it is not an array of items which is passed into the function - it is only the pointer. So, the sizeof(result) expression will return value 4 or 8 (the size of the pointer in a 32-bit/64-bit system).


Chromium

V511 The sizeof() operator returns size of the pointer, and not of the array, in 'sizeof (salt)' expression. browser visitedlink_master.cc 968


uint8 salt_[LINK_SALT_LENGTH];

VisitedLinkMaster::TableBuilder::TableBuilder(
    VisitedLinkMaster* master,
    const uint8 salt[LINK_SALT_LENGTH])
    : master_(master),
      success_(true) {
  fingerprints_.reserve(4096);
  memcpy(salt_, salt, sizeof(salt));
}

The 'salt' object is simply a pointer. Value LINK_SALT_LENGTH in the square brackets indicates to the programmer that he is working with an array of LINK_SALT_LENGTH items. But it is not an array of items which is passed into the function - it is only the pointer. So, the sizeof(salt) expression will return value 4 or 8 (the size of the pointer in a 32-bit/64-bit system).

Similar errors can be found in some other places:

  • V511 The sizeof() operator returns size of the pointer, and not of the array, in 'sizeof (salt)' expression. common visitedlink_common.cc 84

MySQL

V511 The sizeof() operator returns size of the pointer, and not of the array, in 'sizeof (buf)' expression. auth_win_client common.cc 489


typedef char Error_message_buf[1024];

const char* get_last_error_message(Error_message_buf buf)
{
  int error= GetLastError();

  buf[0]= '\0';
  FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM,
  NULL, error, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
  (LPTSTR)buf, sizeof(buf), NULL );

  return buf;
}

The 'buf' object is simply a pointer. So, the sizeof(buf) expression will return value 4 or 8 (the size of the pointer in a 32-bit/64-bit system).


Intel AMT SDK

V511 The sizeof() operator returns size of the pointer, and not of the array, in 'sizeof (pid)' expression. PskGenerator pskgenerator.cpp 126


typedef char PID[pid_len+1];
typedef char PPS[pps_len+1];

static void generate(PID pid, PPS pps)
{
  memset(pid,0,sizeof(pid));
  memset(pps,0,sizeof(pps));
  ....
}

The 'pid/pps' object is simply a pointer. Value pid_len+1 / pps_len+1 in the square brackets indicates to the programmer that he is working with an array of N items. But it is not an array of items which is passed into the function - it is only the pointer. So, the sizeof(pid) / sizeof(pps) expression will return value 4 or 8 (the size of the pointer in a 32-bit/64-bit system).

Similar errors can be found in some other places:

  • V511 The sizeof() operator returns size of the pointer, and not of the array, in 'sizeof (pps)' expression. PskGenerator pskgenerator.cpp 127

ReactOS

V511 The sizeof() operator returns size of the pointer, and not of the array, in 'sizeof (dest)' expression. glu32 mapdesc.cc 95


void
Mapdesc::identify( REAL dest[MAXCOORDS][MAXCOORDS] )
{
  memset( dest, 0, sizeof( dest ) );
  for( int i=0; i != hcoords; i++ )
    dest[i][i] = 1.0;
}

The 'dest' object is simply a pointer. Value [MAXCOORDS][MAXCOORDS] in the square brackets indicates to the programmer that he is working with an array of MAXCOORDS x MAXCOORDS items. But it is not an array of items which is passed into the function - it is only the pointer. So, the sizeof(dest) expression will return value 4 or 8 (the size of the pointer in a 32-bit/64-bit system). This is what should have been written here: Mapdesc::identify( REAL (&dest)[MAXCOORDS][MAXCOORDS] )


Samba

V511 The sizeof() operator returns size of the pointer, and not of the array, in 'sizeof ((domain))' expression. wbinfo.c 124


#define FSTRING_LEN 256
typedef char fstring[FSTRING_LEN];

char *safe_strcpy(char *dest,const char *src, size_t maxlength)
#define fstrcpy(d,s) safe_strcpy((d),(s),sizeof(fstring)-1)

static bool parse_wbinfo_domain_user(
  const char *domuser, fstring domain, fstring user)
{
  ....
    /* Maybe it was a UPN? */
    if ((p = strchr(domuser, '@')) != NULL) {
      fstrcpy(domain, "");
      fstrcpy(user, domuser);
      return true;
    }
  ....
}

Similar errors can be found in some other places:

  • V511 The sizeof() operator returns size of the pointer, and not of the array, in 'sizeof ((user))' expression. wbinfo.c 125
  • V511 The sizeof() operator returns size of the pointer, and not of the array, in 'sizeof ((user))' expression. wbinfo.c 129
  • V511 The sizeof() operator returns size of the pointer, and not of the array, in 'sizeof ((domain))' expression. wbinfo.c 130
  • And 22 additional diagnostic messages.

Source Engine SDK

V511 The sizeof() operator returns size of the pointer, and not of the array, in 'sizeof (iNeighbors)' expression. Vrad_dll disp_vrad.cpp 60


#define RTL_NUMBER_OF_V1(A) (sizeof(A)/sizeof((A)[0]))
#define _ARRAYSIZE(A)   RTL_NUMBER_OF_V1(A)

int GetAllNeighbors( const CCoreDispInfo *pDisp,
                     int iNeighbors[512] )
{
  ....
  if ( nNeighbors < _ARRAYSIZE( iNeighbors ) )
    iNeighbors[nNeighbors++] = pCorner->m_Neighbors[i];
  ....
}

Oracle VM Virtual Box

V511 The sizeof() operator returns size of the pointer, and not of the array, in 'sizeof (plane)' expression. devvga-svga3d-win.cpp 4650


int vmsvga3dSetClipPlane(...., float plane[4]) // <=
{
  ....
  /* Store for vm state save/restore. */
  pContext->state.aClipPlane[index].fValid = true;
  memcpy(pContext->state.aClipPlane[....], plane, sizeof(plane));
  ....
}

Popular related articles
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…
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…
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…
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…
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…
PVS-Studio for Java

Date: Jan 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…
Static analysis as part of the development process in Unreal Engine

Date: Jun 27 2017

Author: Andrey Karpov

Unreal Engine continues to develop as new code is added and previously written code is changed. What is the inevitable consequence of ongoing development in a project? The emergence of new bugs in th…
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…
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…
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…

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