PVS-StudioWarnings

PVS-Studio warning V502 for gridctrl_redux

Nov 19th, 2014
158
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.22 KB | None | 0 0
  1. void CGridCtrlDemoDlg::UpdateMenuUI()
  2. {
  3.   ...
  4.   GetMenu()->CheckMenuItem(IDC_HORZ_LINES, MF_BYCOMMAND |
  5.     (bHorzLines)? MF_CHECKED: MF_UNCHECKED);
  6.   GetMenu()->CheckMenuItem(IDC_LISTMODE, MF_BYCOMMAND |
  7.     (m_Grid.GetListMode())? MF_CHECKED: MF_UNCHECKED);
  8.   GetMenu()->CheckMenuItem(IDC_VERT_LINES, MF_BYCOMMAND |
  9.     (bVertLines)? MF_CHECKED: MF_UNCHECKED);
  10.   GetMenu()->EnableMenuItem(IDC_SINGLESELMODE, MF_BYCOMMAND |
  11.     (m_Grid.GetListMode())? MF_ENABLED: MF_DISABLED|MF_GRAYED);
  12.   .....
  13.   GetMenu()->CheckMenuItem(ID_HIDE2NDROWCOLUMN,
  14.     MF_BYCOMMAND |
  15.     (m_bRow2Col2Hidden)? MF_CHECKED: MF_UNCHECKED);
  16.   ...
  17. }
  18.  
  19. This code is incorrect as the priority of '?:' operator is lower than of '|'.
  20. The program works correctly because of MF_BYCOMMAND == 0.
  21. Nonetheless this code is potentially dangerous.
  22.  
  23. This suspicious code was found in gridctrl_redux project by PVS-Studio static code analyzer.
  24. Warning message is:
  25. V502 Perhaps the '?:' operator works in a different way than it was expected. The '?:' operator has a lower priority than the '|' operator.
  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