Examples of errors detected by the V506 diagnostic.


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


WinSCP

V506 Pointer to local variable 'EditorList' is stored outside the scope of this variable. Such a pointer will become invalid. customscpexplorer.cpp 2633


void __fastcall TCustomScpExplorerForm::EditorAutoConfig()
{
  ....
  else
  {
    ....
    TEditorList EditorList;
    EditorList = *WinConfiguration->EditorList;
    EditorList.Insert(0, new TEditorPreferences(EditorData));
    WinConfiguration->EditorList = &EditorList;
  }
  ....
}

Miranda NG

V506 Pointer to local variable 'psr' is stored outside the scope of this variable. Such a pointer will become invalid. Miranda findadd.cpp 777


static INT_PTR CALLBACK DlgProcFindAdd(....)
{
  ....
  case IDC_ADD:
    {
      ADDCONTACTSTRUCT acs = {0};

      if (ListView_GetSelectedCount(hwndList) == 1) {
        ....
      }
      else {
        ....
        PROTOSEARCHRESULT psr = { 0 };                 // <=
        psr.cbSize = sizeof(psr);
        psr.flags = PSR_TCHAR;
        psr.id = str;

        acs.psr = &psr;                                // <=
        acs.szProto = (char*)SendDlgItemMessage(....);
      }
      acs.handleType = HANDLE_SEARCHRESULT;
      CallService(MS_ADDCONTACT_SHOW,
                  (WPARAM)hwndDlg, (LPARAM)&acs;);
    }
    break;
  ....
}

Similar errors can be found in some other places:

  • V506 Pointer to local variable 'blend' is stored outside the scope of this variable. Such a pointer will become invalid. AdvaImg background.cpp 269
  • V506 Pointer to local variable 'aiw' is stored outside the scope of this variable. Such a pointer will become invalid. mir_core protos.cpp 72

Unreal Engine 4

V506 Pointer to local variable 'NewBitmap' is stored outside the scope of this variable. Such a pointer will become invalid. fontcache.cpp 466


void GetRenderData(....)
{
  ....
  if( Slot->bitmap.pixel_mode == FT_PIXEL_MODE_MONO )
  {
    FT_Bitmap NewBitmap;
    ....
    Bitmap = &NewBitmap;
  }
  ....
  OutRenderData.RawPixels.AddUninitialized(
    Bitmap->rows * Bitmap->width );
  ....
}

PHP:Hypertext Preprocessor

V506 Pointer to local variable 'tmp' is stored outside the scope of this variable. Such a pointer will become invalid. spl_fixedarray.c 420


static void
spl_fixedarray_object_write_dimension(
  zval *object, zval *offset, zval *value)
{
  ....
  if (intern->fptr_offset_set) {
    zval tmp;
    if (!offset) {
      ZVAL_NULL(&tmp;);
      offset = &tmp;
    } else {
      SEPARATE_ARG_IF_REF(offset);
  }
  ....
  spl_fixedarray_object_write_dimension_helper(
    intern, offset, value)
}


Do you make errors in the code?

Check your code
with PVS-Studio

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

goto PVS-Studio;