PVS-StudioWarnings

PVS-Studio warning V511 for ReactOS

Nov 17th, 2014
182
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.04 KB | None | 0 0
  1. void
  2. Mapdesc::identify( REAL dest[MAXCOORDS][MAXCOORDS] )
  3. {
  4.   memset( dest, 0, sizeof( dest ) );
  5.   for( int i=0; i != hcoords; i++ )
  6.     dest[i][i] = 1.0;
  7. }
  8.  
  9. The 'dest' object is simply a pointer. Value [MAXCOORDS][MAXCOORDS] in the square brackets indicates to the programmer that he is working with an array of MAXCOORDS x MAXCOORDS items.
  10. But it is not an array of items which is passed into the function - it is only the pointer.
  11. So, the sizeof(dest) expression will return value 4 or 8 (the size of the pointer in a 32-bit/64-bit system).
  12. This is what should have been written here: Mapdesc::identify( REAL (&dest)[MAXCOORDS][MAXCOORDS] )
  13.  
  14. This suspicious code was found in ReactOS project by PVS-Studio static code analyzer.
  15. Warning message is:
  16. V511 The sizeof() operator returns size of the pointer, and not of the array, in 'sizeof (dest)' expression. glu32 mapdesc.cc 95
  17.  
  18. 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