PVS-StudioWarnings

PVS-Studio warning V511 for MySQL

Nov 12th, 2014
154
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.82 KB | None | 0 0
  1. const char* get_last_error_message(Error_message_buf buf)
  2. {
  3.   int error= GetLastError();
  4.  
  5.   buf[0]= '\0';
  6.   FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM,
  7.   NULL, error, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
  8.   (LPTSTR)buf, sizeof(buf), NULL );
  9.  
  10.   return buf;
  11. }
  12.  
  13. The 'buf' object is simply a pointer.
  14. So, the sizeof(buf) expression will return value 4 or 8 (the size of the pointer in a 32-bit/64-bit system).
  15.  
  16. This suspicious code was found in MySQL project by PVS-Studio static code analyzer.
  17. Warning message is:
  18. V511 The sizeof() operator returns size of the pointer, and not of the array, in 'sizeof (buf)' expression. auth_win_client common.cc 489
  19.  
  20. 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