PVS-StudioWarnings

PVS-Studio warning V501 for WebKit

Nov 17th, 2014
192
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.80 KB | None | 0 0
  1. // This method checks if |start| and
  2. // |dest| have a partial intersection, either
  3. // horizontally or vertically.
  4. // * a = Current focused node's rect.
  5. // * b = Focus candidate node's rect.
  6. static bool areRectsPartiallyAligned(....)
  7. {
  8.     int aStart  = start(direction, a);
  9.     int bStart  = start(direction, b);
  10.     int bMiddle = middle(direction, b);
  11.     int aEnd = end(direction, a);
  12.     int bEnd = end(direction, b);
  13.  
  14.     // Picture of the partially aligned logic:
  15.     //
  16.     //    Horizontal       Vertical
  17.     // ********************************
  18.     // *  _            *   _ _ _      *
  19.     // * |_|           *  |_|_|_|     *
  20.     // * |_|.... _     *      . .     *
  21.     // * |_|    |_|    *      . .     *
  22.     // * |_|....|_|    *      ._._ _  *
  23.     // *        |_|    *      |_|_|_| *
  24.     // *        |_|    *              *
  25.     // *               *              *
  26.     // ********************************
  27.     //
  28.     // ... and variants of the above cases.
  29.     return ((bStart >= aStart && bStart <= aEnd)
  30.             || (bStart >= aStart && bStart <= aEnd)
  31.             || (bEnd >= aStart && bEnd <= aEnd)
  32.             || (bMiddle >= aStart && bMiddle <= aEnd)
  33.             || (bEnd >= aStart && bEnd <= aEnd));
  34. }
  35.  
  36. The (bStart >= aStart && bStart <= aEnd) comparison is repeated twice. I cannot say for sure what should be written instead of this.
  37.  
  38. This suspicious code was found in WebKit project by PVS-Studio static code analyzer.
  39. Warning message is:
  40. V501 There are identical sub-expressions '(bStart >= aStart && bStart <= aEnd)' to the left and to the right of the '||' operator. webcore_remaining spatialnavigation.cpp 236
  41.  
  42. 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