PVS-StudioWarnings

PVS-Studio warning V511 for Chromium

Nov 17th, 2014
216
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.06 KB | None | 0 0
  1. uint8 salt_[LINK_SALT_LENGTH];
  2.  
  3. VisitedLinkMaster::TableBuilder::TableBuilder(
  4.     VisitedLinkMaster* master,
  5.     const uint8 salt[LINK_SALT_LENGTH])
  6.     : master_(master),
  7.       success_(true) {
  8.   fingerprints_.reserve(4096);
  9.   memcpy(salt_, salt, sizeof(salt));
  10. }
  11.  
  12. The 'salt' object is simply a pointer. Value LINK_SALT_LENGTH in the square brackets indicates to the programmer that he is working with an array of LINK_SALT_LENGTH items.
  13. But it is not an array of items which is passed into the function - it is only the pointer.
  14. So, the sizeof(salt) expression will return value 4 or 8 (the size of the pointer in a 32-bit/64-bit system).
  15.  
  16.  
  17. This suspicious code was found in Chromium project by PVS-Studio static code analyzer.
  18. Warning message is:
  19. V511 The sizeof() operator returns size of the pointer, and not of the array, in 'sizeof (salt)' expression.  browser  visitedlink_master.cc  968
  20.  
  21. 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