PVS-StudioWarnings

PVS-Studio warning V511 for amtsdk

Nov 10th, 2014
165
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.96 KB | None | 0 0
  1. typedef char PID[pid_len+1];
  2. typedef char PPS[pps_len+1];
  3.  
  4. static void generate(PID pid, PPS pps)
  5. {
  6.   memset(pid,0,sizeof(pid));
  7.   memset(pps,0,sizeof(pps));
  8.   ...
  9. }
  10.  
  11. The 'pid/pps' object is simply a pointer. Value pid_len+1 / pps_len+1 in the square brackets indicates to the programmer that he is working with an array of N items.
  12. But it is not an array of items which is passed into the function - it is only the pointer.
  13. So, the sizeof(pid) / sizeof(pps) expression will return value 4 or 8 (the size of the pointer in a 32-bit/64-bit system).
  14.  
  15. This suspicious code was found in amtsdk project by PVS-Studio static code analyzer.
  16. Warning message is:
  17. V511 The sizeof() operator returns size of the pointer, and not of the array, in 'sizeof (pid)' expression. PskGenerator pskgenerator.cpp 126
  18.  
  19. 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