PVS-StudioWarnings

PVS-Studio warning V511 for Shareaza

Nov 12th, 2014
154
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.06 KB | None | 0 0
  1. #define countof(array) (sizeof(array) / sizeof((array)[0]))
  2.  
  3. size_t AnsiDecodeChar(const BYTE* pBytes,
  4.   size_t nNumBytes, TCHAR arrChar[2],
  5.   size_t& nCharSize)
  6. {
  7.   ....
  8.     nCharSize = MultiByteToWideChar(CP_ACP, 0,
  9.       (const CHAR*)pBytes, nNumBytesInChar,
  10.       arrChar, countof(arrChar));
  11.   ....
  12. }
  13.  
  14. 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.
  15. But it is not an array of items which is passed into the function - it is only the pointer.
  16. So, the sizeof(arrChar) expression will return value 4 or 8 (the size of the pointer in a 32-bit/64-bit system).
  17.  
  18. This suspicious code was found in Shareaza project by PVS-Studio static code analyzer.
  19. Warning message is:
  20. V511 The sizeof() operator returns size of the pointer, and not of the array, in 'sizeof ( arrChar )' expression. BugTrap encoding.cpp 477
  21.  
  22. PVS-Studio is a static analyzer for detecting bugs in the source code of applications written in C, C++, C++11, C++/CX. Site: http://www.viva64.com/en/pvs-studio/
Advertisement
Add Comment
Please, Sign In to add comment