PVS-StudioWarnings

PVS-Studio warning V531 for XuiFramework

Nov 17th, 2014
172
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.91 KB | None | 0 0
  1. CPPString CPPHtmlDrawer::GetStringFromDll(....)
  2. {
  3.   ...
  4.   TCHAR szTemp[256];
  5.  
  6.   DWORD dwLen = ::LoadString(hInstDll, dwID,
  7.     szTemp, (sizeof(szTemp) * sizeof(TCHAR)));
  8.   ...
  9. }
  10.  
  11. The LoadString function takes the buffer's size in characters as the last argument. In the Unicode version of the application, we will tell the function that the buffer's size is larger than it is actually. This may cause a buffer overflow. Note that if we fix the code in the following way, it will not become correct at all: sizeof(szTemp) / sizeof(TCHAR).
  12.  
  13.  
  14. This suspicious code was found in XuiFramework project by PVS-Studio static code analyzer.
  15. Warning message is:
  16. V531 It is odd that a sizeof() operator is multiplied by sizeof(). Borne pphtmldrawer.cpp 258
  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