Advertisement
PVS-StudioWarnings

PVS-Studio warning V510 for WinMerge

Nov 24th, 2014
183
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.85 KB | None | 0 0
  1. String GetSysError(int nerr);
  2. ...
  3. CString msg;
  4. msg.Format(
  5. _T("Failed to open registry key HKCU/%s:\n\t%d : %s"),
  6. f_RegDir, retVal, GetSysError(retVal));
  7.  
  8. Everything looks fine at the first sight. But the "String" type is nothing but "std::wstring". Therefore, we will get some gibberish printed at best and an Access Violation error at worst. An object of the "std::wstring" type is placed instead of the string pointer into the stack. The correct code should contain a call of c_str():
  9.  
  10. This suspicious code was found in WinMerge project by PVS-Studio static code analyzer.
  11. Warning message is:
  12. V510 The 'Format' function is not expected to receive class-type variable as 'N' actual argument
  13.  
  14. 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
Advertisement