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

Examples of errors detected by the V507 diagnostic

Apr 05 2021

V507. Pointer to local array 'X' is stored outside the scope of this array. Such a pointer will become invalid.


TortoiseSVN

V507 Pointer to local array 'stringbuf' is stored outside the scope of this array. Such a pointer will become invalid. mainwindow.cpp 277


LRESULT CALLBACK CMainWindow::WinMsgHandler(....)
{
  ....
  if (pNMHDR->code == TTN_GETDISPINFO)
  {
    LPTOOLTIPTEXT lpttt;

    lpttt = (LPTOOLTIPTEXT) lParam;
    lpttt->hinst = hResource;

    // Specify the resource identifier of the
    // descriptive text for the given button.
    TCHAR stringbuf[MAX_PATH] = {0};
    ....
    lpttt->lpszText = stringbuf;
  }
  ....
}

It's not that simple with this code. Theoretically, the code contains an error. Practically, it works well. The V507 diagnostic message warns you that an object is used after being destroyed. The 'stringbuf' buffer will be used after exiting the body of the 'if' operator. If 'stringbuf' was an object of the class std::string, for instance, its behavior would be incorrect. We would use an already destroyed object in that case. But here 'stringbuf' is an array created in the stack. The Visual C++ compiler doesn't use this stack area again, so the buffer will exist until the 'CMainWindow::WinMsgHandler' function finishes its work. Thus, no error occurs, although the code is potentially dangerous.

Similar errors can be found in some other places:

  • V507 Pointer to local array 'stringbuf' is stored outside the scope of this array. Such a pointer will become invalid. picwindow.cpp 443

Pixie

V507 Pointer to local array 'var' is stored outside the scope of this array. Such a pointer will become invalid. ri renderer.cpp 5974


class CVariable {
public:
  char  name[64];  // Name as it is referenced
  ....
};

void CRendererContext::RiGeometryV(
  char *type,int n,char *tokens[],void *params[])
{
  ....
  } else {
    CVariable var;
    if (parseVariable(&var,NULL,tokens[i])) {
      tokens[i] = var.name;
      i--;
    } else {
      error(CODE_BADTOKEN,
            "Unrecognised implicit parameter: %s\n",tokens[i]);
    }
  }
  ....
}

Similar errors can be found in some other places:

  • V507 Pointer to local array 'var' is stored outside the scope of this array. Such a pointer will become invalid. ri renderer.cpp 6010

MySQL

V507 Pointer to local array 'buf' is stored outside the scope of this array. Such a pointer will become invalid. myisam ha_myisam.cc 1156


int ha_myisam::assign_to_keycache(THD* thd,
                                  HA_CHECK_OPT *check_opt)
{
  ....
  const char *errmsg= 0;
  ....
  if ((error= mi_assign_to_key_cache(file, map, new_key_cache)))
  {
    char buf[STRING_BUFFER_USUAL_SIZE];
    my_snprintf(buf, sizeof(buf),
      "Failed to flush to index file (errno: %d)", error);
    errmsg = buf;
    error = HA_ADMIN_CORRUPT;
  }
  ....
}

It's not that simple with this code. Theoretically, the code contains an error. Practically, it works well. The V507 diagnostic message warns you that an object is used after being destroyed. The 'buf' buffer will be used after exiting the body of the 'if' operator. If 'buf' was an object of the class std::string, for instance, its behavior would be incorrect. We would use an already destroyed object in that case. But here 'buf' is an array created in the stack. The Visual C++ compiler doesn't use this stack area again, so the buffer will exist until the 'ha_myisam::assign_to_keycache' function finishes its work. Thus, no error occurs, although the code is potentially dangerous.


Source Engine SDK

V507 Pointer to local array 'szActName' is stored outside the scope of this array. Such a pointer will become invalid. Server (HL2) baseflex.cpp 1326


static Activity DetermineExpressionMoveActivity(
  CChoreoEvent *event, CAI_BaseNPC *pNPC )
{
  ....
  const char *pszAct = Q_strstr( sParam2, " " );
  if ( pszAct )
  {
    char szActName[256];
    Q_strncpy( szActName, sParam2, sizeof(szActName) );
    szActName[ (pszAct-sParam2) ] = '\0';
    pszAct = szActName;
  }
  ....
}

Scilab

V507 Pointer to local array 'strfl' is stored outside the scope of this array. Such a pointer will become invalid. sci_champ.c 103


int sci_champ_G(....)
{
  ....
  char * strf = NULL ;
  ....
  if ( isDefStrf( strf ) )
  {
    char strfl[4];
    strcpy(strfl,DEFSTRFN);
    strf = strfl;
    if ( !isDefRect( rect ) )
    {
      strf[1]='5';
    }
  }

  (*func)(stk(l1 ),stk(l2 ),stk(l3 ),stk(l4 ),
    &m3,&n3,strf,rect, arfact, 4L);
  ....
}

Similar errors can be found in some other places:

  • V507 Pointer to local array 'strfl' is stored outside the scope of this array. Such a pointer will become invalid. sci_fec.c 111
  • V507 Pointer to local array 'strfl' is stored outside the scope of this array. Such a pointer will become invalid. sci_grayplot.c 94
  • V507 Pointer to local array 'strfl' is stored outside the scope of this array. Such a pointer will become invalid. sci_matplot.c 84

Miranda NG

V507 Pointer to local array 'str' is stored outside the scope of this array. Such a pointer will become invalid. Miranda genmenu.cpp 973


HMENU BuildRecursiveMenu(....)
{
  ....
  if (GetKeyState(VK_CONTROL) & 0x8000) {
    TCHAR str[256];

    mir_sntprintf(str, SIZEOF(str),
      _T("%s (%d, id %x)"), mi->pszName,
      mi->position, mii.dwItemData);

    mii.dwTypeData = str;
  }
  ....
}

Similar errors can be found in some other places:

  • V507 Pointer to local array 'str' is stored outside the scope of this array. Such a pointer will become invalid. Miranda genmenu.cpp 988
  • V507 Pointer to local array 'szFiles' is stored outside the scope of this array. Such a pointer will become invalid. ICQ icq_proto.cpp 1323
  • V507 Pointer to local array 'jidreason' is stored outside the scope of this array. Such a pointer will become invalid. Jabber jabber_iqid_muc.cpp 121
  • And 4 additional diagnostic messages.

MAME

V507 Pointer to local array 'label' is stored outside the scope of this array. Such a pointer will become invalid. usrintrf.c 2121


static int settraksettings(struct mame_bitmap *bitmap,
                           int selected)
{
  const char *menu_item[40];
  const char *menu_subitem[40];
  ....
  for (i = 0;i < total2;i++)
  {
    if (i < total2 - 1)
    {
      char label[30][40];
      char setting[30][40];
      ....
      menu_item[i] = label[i];
      menu_subitem[i] = setting[i];
    }
  }
  ....
}

Similar errors can be found in some other places:

  • V507 Pointer to local array 'setting' is stored outside the scope of this array. Such a pointer will become invalid. usrintrf.c 2122

GNU Octave

V507 Pointer to local array 'dirbuf' is stored outside the scope of this array. Such a pointer will become invalid. tmpdir.c 128


int path_search(const char *dir, ....)
{
  ....
  if (....)
  {
    char dirbuf[PATH_MAX];
    ....
    dir = dirbuf;
  }
  ....
  dlen = strlen (dir);
}

Inkscape

V507 Pointer to local array 'n' is stored outside the scope of this array. Such a pointer will become invalid. inkscape.cpp 582


void
Application::crash_handler(int /*signum*/)
{
  ....
  if (doc->isModifiedSinceSave()) {
    const gchar *docname;
  ....
  if (docname) {
    ....
    if (*d=='.' && d>docname && dots==2) {
      char n[64];
      size_t len = MIN (d - docname, 63);
      memcpy (n, docname, len);
      n[len] = '\0';
      docname = n;
    }
  }
  if (!docname || !*docname) docname = "emergency";
  ....
}

Similar errors can be found in some other places:

  • V507 Pointer to local array 'in_buffer' is stored outside the scope of this array. Such a pointer will become invalid. inkjar.cpp 371
  • V507 Pointer to local array 'out_buffer' is stored outside the scope of this array. Such a pointer will become invalid. inkjar.cpp 375

GCC

V507 Pointer to local array 'buf' is stored outside the scope of this array. Such a pointer will become invalid. hsa-dump.c 704


static void
dump_hsa_symbol (FILE *f, hsa_symbol *symbol)
{
  const char *name;
  if (symbol->m_name)
    name = symbol->m_name;
  else
  {
    char buf[64];
    sprintf (buf, "__%s_%i", hsa_seg_name (symbol->m_segment),
       symbol->m_name_number);
     name = buf;
  }

  fprintf (f, "align(%u) %s_%s %s",
           hsa_byte_alignment (symbol->m_align),
           hsa_seg_name(symbol->m_segment),
           hsa_type_name(symbol->m_type & ~BRIG_TYPE_ARRAY_MASK),
           name);
  ....
}

Tizen

V507 Pointer to local array 'buffer' is stored outside the scope of this array. Such a pointer will become invalid. media_codec_test.c 793


void extract_input_aacdec_m4a_test(
  App * app, unsigned char **data, int *size, bool * have_frame)
{
  ....
  unsigned char buffer[100000];
  ....
DONE:
  *data = buffer;
  *have_frame = TRUE;
  if (read_size >= offset)
    *size = offset;
  else
    *size = read_size;
}

Android

V507 CWE-562 Pointer to local array 'buf' is stored outside the scope of this array. Such a pointer will become invalid. transport.cpp 1030


int register_socket_transport(int s, const char* serial, int port, int local) {
  atransport* t = new atransport();

  if (!serial) {
    char buf[32];
    snprintf(buf, sizeof(buf), "T-%p", t);
    serial = buf;
  }
  ....
}

Doom 1

V507 [CWE-562] Pointer to local array 'clipbot' is stored outside the scope of this array. Such a pointer will become invalid. r_things.c 947


short *mfloorclip;
short *mceilingclip;
void R_DrawSprite (vissprite_t* spr)
{
  short clipbot[SCREENWIDTH];
  short cliptop[SCREENWIDTH];
  ....
  mfloorclip = clipbot;
  mceilingclip = cliptop;
  R_DrawVisSprite (spr, spr->x1, spr->x2);
}

Similar errors can be found in some other places:

  • V507 [CWE-562] Pointer to local array 'cliptop' is stored outside the scope of this array. Such a pointer will become invalid. r_things.c 948

Command & Conquer

V507 Pointer to local array 'localpalette' is stored outside the scope of this array. Such a pointer will become invalid. MAPSEL.CPP 757


extern "C" unsigned char *InterpolationPalette;

void Map_Selection(void)
{
  unsigned char localpalette[768];
  ....
  InterpolationPalette = localpalette;
  ....
}

Similar errors can be found in some other places:

  • V507 Pointer to local array 'localpalette' is stored outside the scope of this array. Such a pointer will become invalid. MAPSEL.CPP 769
  • V507 Pointer to local array 'buffer' is stored outside the scope of this array. Such a pointer will become invalid. WINDOWS.CPP 458

Popular related articles
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 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…
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…
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…
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…
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…
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 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 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…
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…

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