PVS-StudioWarnings

PVS-Studio warning V557 for Miranda IM

Nov 24th, 2014
202
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.82 KB | None | 0 0
  1. const int idToIndex(const int id) const
  2. {
  3.   for(int i = 0; i < NR_BUTTONS; i++) {
  4.     if(m_TbButtons[i].idCommand == id )
  5.       return(i);
  6.   }
  7.   return(-1);
  8. }
  9.  
  10. TBBUTTON CMenuBar::m_TbButtons[8] = {0};
  11.  
  12. void CMenuBar::invoke(const int id)
  13. {
  14.   const int index = idToIndex(id);
  15.   ....
  16.   if(index == 3 && hContact != 0) {
  17.     ....
  18.   } else if(index == 0) {
  19.     ....
  20.   } else
  21.     hMenu = reinterpret_cast<HMENU>(m_TbButtons[index].dwData);
  22.   ....
  23. }
  24.  
  25. This suspicious code was found in Miranda IM project by PVS-Studio static code analyzer.
  26. Warning message is:
  27. V557 Array underrun is possible. The value of 'index' index could reach -1. controls.cpp 491
  28.  
  29. 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