PVS-StudioWarnings

PVS-Studio warning V579 for CamStudio

Nov 12th, 2014
154
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.99 KB | None | 0 0
  1. LONG GetRegKey (HKEY key, LPCTSTR subkey, LPTSTR retdata)
  2. {
  3.   HKEY hkey;
  4.   LONG retval = ::RegOpenKeyEx (key, subkey,
  5.     0, KEY_QUERY_VALUE, &hkey);
  6.   if (retval == ERROR_SUCCESS)
  7.   {
  8.     long datasize = MAX_PATH;
  9.     TCHAR data[MAX_PATH];
  10.     ::RegQueryValue (hkey, NULL, data, &datasize);
  11.     // Cause C4996 warning, marked as deprecation candidate
  12.     // _tcscpy (retdata, data);
  13.     // Safe replacement
  14.     strcpy_s(retdata, sizeof(retdata), data );
  15.     ::RegCloseKey (hkey);
  16.   }
  17.   return retval;
  18. }
  19.  
  20. It was right but unsafe. Then they made it safe but not right :)
  21.  
  22. This suspicious code was found in CamStudio project by PVS-Studio static code analyzer.
  23. Warning message is:
  24. V579 The strcpy_s function receives the pointer and its size as arguments. It is possibly a mistake. Inspect the second argument. camsys.cpp 39
  25.  
  26. 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