PVS-StudioWarnings

PVS-Studio warning V610 for MAME

Nov 17th, 2014
232
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.27 KB | None | 0 0
  1. UINT32 m_color1_mask;
  2. UINT32 m_color2_mask;
  3.  
  4. #define ARRAY_LENGTH(x) (sizeof(x) / sizeof(x[0]))
  5.  
  6. PALETTE_INIT( montecar )
  7. {
  8.  static const UINT8 colortable_source[] =
  9.  {
  10.   0x00, 0x00, 0x00, 0x01,
  11.   0x00, 0x02, 0x00, 0x03,
  12.   0x03, 0x03, 0x03, 0x02,
  13.   0x03, 0x01, 0x03, 0x00,
  14.   0x00, 0x00, 0x02, 0x00,
  15.   0x02, 0x01, 0x02, 0x02,
  16.   0x00, 0x10, 0x20, 0x30,
  17.   0x00, 0x04, 0x08, 0x0c,
  18.   0x00, 0x44, 0x48, 0x4c,
  19.   0x00, 0x84, 0x88, 0x8c,
  20.   0x00, 0xc4, 0xc8, 0xcc
  21.  };
  22.   ...
  23.  for (i = 0; i < ARRAY_LENGTH(colortable_source); i++)
  24.  {
  25.   UINT8 color = colortable_source[i];
  26.  
  27.   if (color == 1)
  28.    state->m_color1_mask |= 1 << i;                  <<<---
  29.   else if (color == 2)
  30.    state->m_color2_mask |= 1 << i;                  <<<---
  31.  
  32.   prom_to_palette(machine, i,
  33.     color_prom[0x100 + colortable_source[i]]);
  34.  }
  35.   ...
  36. }
  37.  
  38. This suspicious code was found in MAME project by PVS-Studio static code analyzer.
  39. Warning message is:
  40. V610 Undefined behavior. Check the shift operator '<<. The right operand ('i' = [0..43]) is greater than or equal to the length in bits of the promoted left operand.  firetrk.c 111
  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