Advertisement
PVS-StudioWarnings

PVS-Studio warning V530 for TortoiseSVN

Nov 25th, 2014
168
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.38 KB | None | 0 0
  1. STDMETHODIMP CShellExt::Initialize(....)
  2. {
  3.   ...
  4.   ignoredprops.empty();
  5.   for (int p=0; p<props.GetCount(); ++p)
  6.   {
  7.     if (props.GetItemName(p).
  8.           compare(SVN_PROP_IGNORE)==0)
  9.     {
  10.       std::string st = props.GetItemValue(p);
  11.       ignoredprops = UTF8ToWide(st.c_str());
  12.       // remove all escape chars ('\\')
  13.       std::remove(ignoredprops.begin(),
  14.                   ignoredprops.end(), '\\');
  15.       break;
  16.     }
  17.   }
  18.   ...
  19. }
  20.  
  21. The std::remove function does not remove elements from the container. It only shifts the elements and brings the iterator back to the beginning of the trash. Suppose we have the vector<int> container that contains elements 1,2,3,1,2,3,1,2,3. If we execute the code "remove( v.begin(), v.end(), 2 )", the container will contain elements 1,3,1,3,?,?,?, where ? is some trash. The function will bring the iterator back to the first senseless element, so if we want to remove these trash elements, we must write the code this way: "v.erase(remove(v.begin(), v.end(), 2), v.end())".
  22.  
  23. This suspicious code was found in TortoiseSVN project by PVS-Studio static code analyzer.
  24. Warning message is:
  25. V530 The return value of function 'empty' is required to be utilized. contextmenu.cpp 434
  26.  
  27. 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