Examples of errors detected by the V620 diagnostic.


V620. It's unusual that the expression of sizeof(T)*N kind is being summed with the pointer to T type.


Apache Xerces Project

V620 It's unusual that the expression of sizeof(T) kind is being subtracted from the pointer to T type. domnormalizer.cpp 277


const XMLCh *DOMNormalizer::integerToXMLCh(unsigned int i) const
{
  XMLCh *buf = (XMLCh*)
               fMemoryManager->allocate(15 * sizeof(XMLCh));
  XMLCh *pos = buf + sizeof(buf) - sizeof(XMLCh);
  ....
}

Snes9x

V620 It's unusual that the expression of sizeof(T) kind is being summed with the pointer to T type. wsnes9x.cpp 6145


typedef wchar_t TCHAR;

INT_PTR CALLBACK DlgOpenROMProc(....)
{
  ....
  TCHAR *tmp, *tmp2;
  ....
  while(tmp2=_tcsstr(tmp, TEXT("\\")))
    tmp=tmp2+sizeof(TCHAR);
  ....
}

Most likely this is what should be written here: tmp=tmp2+1;


Miranda NG

V620 It's unusual that the expression of sizeof(T)*N kind is being summed with the pointer to T type. Scriver input.cpp 387


BOOL HandleLinkClick(....)
{
  ....
  MoveMemory(tr.lpstrText + sizeof(TCHAR)* 7,
             tr.lpstrText,
             sizeof(TCHAR)*(tr.chrg.cpMax - tr.chrg.cpMin + 1));
  ....
}

Similar errors can be found in some other places:

  • V620 It's unusual that the expression of sizeof(T)*N kind is being summed with the pointer to T type. UInfoEx ctrl_edit.cpp 351

Chromium

V620 It's unusual that the expression of sizeof(T)*N kind is being summed with the pointer to T type. string_conversion.cc 62


int UTF8ToUTF16Char(const char *in,
                    int in_length,
                    uint16_t out[2])
{
  const UTF8 *source_ptr = reinterpret_cast<const UTF8 *>(in);
  const UTF8 *source_end_ptr = source_ptr + sizeof(char);
  uint16_t *target_ptr = out;
  uint16_t *target_end_ptr =
    target_ptr + 2 * sizeof(uint16_t); // <=
  out[0] = out[1] = 0;
  ....
}

Similar errors can be found in some other places:

  • V620 It's unusual that the expression of sizeof(T)*N kind is being summed with the pointer to T type. string_conversion.cc 106


Do you make errors in the code?

Check your code
with PVS-Studio

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

goto PVS-Studio;