Our website uses cookies to enhance your browsing experience.
Accept
to the top
close form

Fill out the form in 2 simple steps below:

Your contact information:

Step 1
Congratulations! This is your promo code!

Desired license type:

Step 2
Team license
Enterprise license
** By clicking this button you agree to our Privacy Policy statement
close form
Request our prices
New License
License Renewal
--Select currency--
USD
EUR
* By clicking this button you agree to our Privacy Policy statement

close form
Free PVS‑Studio license for Microsoft MVP specialists
* By clicking this button you agree to our Privacy Policy statement

close form
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

close form
I am interested to try it on the platforms:
* By clicking this button you agree to our Privacy Policy statement

close form
check circle
Message submitted.

Your message has been sent. We will email you at


If you do not see the email in your inbox, please check if it is filtered to one of the following folders:

  • Promotion
  • Updates
  • Spam

Webinar: Parsing C++ - 10.10

>
>
>
Examples of errors detected by the V514…

Examples of errors detected by the V514 diagnostic

V514. Potential logical error. Size of a pointer is divided by another value.


Miranda IM

V514 Dividing sizeof a pointer 'sizeof (text)' by another value. There is a probability of logical error presence. clist_modern modern_cachefuncs.cpp 567


#define SIZEOF(X) (sizeof(X)/sizeof(X[0]))

int Cache_GetLineText(..., LPTSTR text, int text_size, ...)
{
  ....
  tmi.printDateTime(pdnce->hTimeZone, _T("t"), text,
                    SIZEOF(text), 0);
  ....
}

Most likely this is what should be written here: tmi.printDateTime(pdnce->hTimeZone, _T("t"), text, text_size, 0);


ReactOS

V514 Dividing sizeof a pointer 'sizeof (szText)' by another value. There is a probability of logical error presence. shell32 drive.c 126


VOID
GetDriveNameWithLetter(LPWSTR szText, UINT Length, WCHAR Drive)
{
  ....
  TempLength = LoadStringW(shell32_hInstance,
    IDS_DRIVE_FIXED, &szText[Length+1],
    (sizeof(szText)/sizeof(WCHAR))- Length - 2);
  ....
}

"sizeof(szText)/sizeof(WCHAR)" - the pointer size is divided by the WCHAR size. The programmer seems to have intended to do some different thing.


Notepad++

V514 Dividing sizeof a pointer 'sizeof (tvi.pszText)' by another value. There is a probability of logical error presence. Notepad++ treeview.cpp 88


typedef struct tagTVITEMA {
  ....
  LPSTR     pszText;
  ....
} TVITEMA, *LPTVITEMA;

#define TVITEM TVITEMA

HTREEITEM TreeView::addItem(....)
{
  TVITEM tvi;
  ....
  tvi.cchTextMax = sizeof(tvi.pszText)/sizeof(tvi.pszText[0]);
  ....
}

ReactOS

V514 Dividing sizeof a pointer 'sizeof (DosDevices.Buffer)' by another value. There is a probability of logical error presence. mountmgr.c 164


typedef struct _UNICODE_STRING {
  USHORT Length;
  USHORT MaximumLength;
  PWSTR  Buffer;
} UNICODE_STRING, *PUNICODE_STRING;

UNICODE_STRING DosDevices =
  RTL_CONSTANT_STRING(L"\\DosDevices\\");

NTSTATUS CreateNewDriveLetterName(....)
{
  ....
  DriveLetter->Buffer[
    sizeof(DosDevices.Buffer) / sizeof(WCHAR)] =
      (WCHAR)Letter;
  ....
}

Similar errors can be found in some other places:

  • V514 Dividing sizeof a pointer 'sizeof (DosDevices.Buffer)' by another value. There is a probability of logical error presence. mountmgr.c 190
  • V514 Dividing sizeof a pointer 'sizeof (DosDevices.Buffer)' by another value. There is a probability of logical error presence. symlink.c 937

OpenMS

V514 Dividing sizeof a pointer 'sizeof (header)' by another value. There is a probability of logical error presence. compressedinputsource.c 52


CompressedInputSource::CompressedInputSource(
  const String & file_path, const char * header,
  MemoryManager * const manager)
  : xercesc::InputSource(manager)
{
  if (sizeof(header) / sizeof(char) > 1)
  {
    head_[0] = header[0];
    head_[1] = header[1];
  }
  else
  {
    head_[0] = '\0';
    head_[1] = '\0';
  }
  ....
}

Similar errors can be found in some other places:

  • V514 Dividing sizeof a pointer 'sizeof (header)' by another value. There is a probability of logical error presence. compressedinputsource.c 104

OpenCOLLADA

V514 Dividing sizeof a pointer 'sizeof (objectGroups)' by another value. There is a probability of logical error presence. mayadmdagnode.h 40


struct ObjectGroups{
  componentList objectGrpCompList;
  int objectGroupId;
  short objectGrpColor;
  void write(FILE* file) const;
}* objectGroups;

void write(FILE* file) const
{
  size_t size = sizeof(objectGroups)/sizeof(ObjectGroups);
  for(size_t i=0; i<size; ++i)
  {
    objectGroups[i].write(file);
    if(i+1<size) fprintf(file," ");
  }
}

Similar errors can be found in some other places:

  • V514 Dividing sizeof a pointer 'sizeof (compObjectGroups)' by another value. There is a probability of logical error presence. mayadmgeometryshape.h 33
  • V514 Dividing sizeof a pointer 'sizeof (uvSetPoints)' by another value. There is a probability of logical error presence. mayadmcontrolpoint.h 27
  • V514 Dividing sizeof a pointer 'sizeof (colorSetPoints)' by another value. There is a probability of logical error presence. mayadmcontrolpoint.h 59
  • And 10 additional diagnostic messages.

Scilab

V514 Dividing sizeof a pointer 'sizeof dictionary' by another value. There is a probability of logical error presence. getcommonpart.c 76


void qsort(
  void *base,
  size_t num,     // Array size in elements.
  size_t width,   // Element size in bytes.
  int (__cdecl *compare )(const void *, const void *)
);

char *getCommonPart(char **dictionary, int sizeDictionary)
{
  ....
  char *currentstr = dictionary[0];
  qsort(dictionary, sizeof dictionary / sizeof dictionary[0],
        sizeof dictionary[0], cmp);
  ....
}

Similar errors can be found in some other places:

  • V514 Dividing sizeof a pointer 'sizeof dictionary' by another value. There is a probability of logical error presence. getfilesdictionary.c 105

Miranda NG

V514 Dividing sizeof a pointer 'sizeof (dbv.ptszVal)' by another value. There is a probability of logical error presence. TranslitSwitcher layoutproc.cpp 827


#define SIZEOF(X) (sizeof(X)/sizeof(X[0]))

TCHAR *ptszVal;

int OnButtonPressed(WPARAM wParam, LPARAM lParam)
{
  ....
  int FinalLen = slen + SIZEOF(dbv.ptszVal) + 1;
  ....
}

Most likely this is what should be written here: int FinalLen = slen + _tstrlen(dbv.ptszVal) + 1;

Similar errors can be found in some other places:

  • V514 Dividing sizeof a pointer 'sizeof (dbv.ptszVal)' by another value. There is a probability of logical error presence. TranslitSwitcher layoutproc.cpp 876
  • V514 Dividing sizeof a pointer 'sizeof (dbv.ptszVal)' by another value. There is a probability of logical error presence. TranslitSwitcher layoutproc.cpp 924
  • V514 Dividing sizeof a pointer 'sizeof (tmp)' by another value. There is a probability of logical error presence. New_GPG main.cpp 1300