fixed undefined signed integer overflow for expression "1 << 31"
[rocksndiamonds.git] / src / editor.c
index bf16751ffef420bdfb72948c17e2fd6daffd1502..833dce2ec7996d81f106a9d3522178bb274753bc 100644 (file)
@@ -2079,38 +2079,38 @@ static struct ValueTextInfo options_change_trigger_player[] =
 
 static struct ValueTextInfo options_change_trigger_page[] =
 {
-  { (1 << 0),                  "1"                             },
-  { (1 << 1),                  "2"                             },
-  { (1 << 2),                  "3"                             },
-  { (1 << 3),                  "4"                             },
-  { (1 << 4),                  "5"                             },
-  { (1 << 5),                  "6"                             },
-  { (1 << 6),                  "7"                             },
-  { (1 << 7),                  "8"                             },
-  { (1 << 8),                  "9"                             },
-  { (1 << 9),                  "10"                            },
-  { (1 << 10),                 "11"                            },
-  { (1 << 11),                 "12"                            },
-  { (1 << 12),                 "13"                            },
-  { (1 << 13),                 "14"                            },
-  { (1 << 14),                 "15"                            },
-  { (1 << 15),                 "16"                            },
-  { (1 << 16),                 "17"                            },
-  { (1 << 17),                 "18"                            },
-  { (1 << 18),                 "19"                            },
-  { (1 << 19),                 "20"                            },
-  { (1 << 20),                 "21"                            },
-  { (1 << 21),                 "22"                            },
-  { (1 << 22),                 "23"                            },
-  { (1 << 23),                 "24"                            },
-  { (1 << 24),                 "25"                            },
-  { (1 << 25),                 "26"                            },
-  { (1 << 26),                 "27"                            },
-  { (1 << 27),                 "28"                            },
-  { (1 << 28),                 "29"                            },
-  { (1 << 29),                 "30"                            },
-  { (1 << 30),                 "31"                            },
-  { (1 << 31),                 "32"                            },
+  { (1u << 0),                 "1"                             },
+  { (1u << 1),                 "2"                             },
+  { (1u << 2),                 "3"                             },
+  { (1u << 3),                 "4"                             },
+  { (1u << 4),                 "5"                             },
+  { (1u << 5),                 "6"                             },
+  { (1u << 6),                 "7"                             },
+  { (1u << 7),                 "8"                             },
+  { (1u << 8),                 "9"                             },
+  { (1u << 9),                 "10"                            },
+  { (1u << 10),                        "11"                            },
+  { (1u << 11),                        "12"                            },
+  { (1u << 12),                        "13"                            },
+  { (1u << 13),                        "14"                            },
+  { (1u << 14),                        "15"                            },
+  { (1u << 15),                        "16"                            },
+  { (1u << 16),                        "17"                            },
+  { (1u << 17),                        "18"                            },
+  { (1u << 18),                        "19"                            },
+  { (1u << 19),                        "20"                            },
+  { (1u << 20),                        "21"                            },
+  { (1u << 21),                        "22"                            },
+  { (1u << 22),                        "23"                            },
+  { (1u << 23),                        "24"                            },
+  { (1u << 24),                        "25"                            },
+  { (1u << 25),                        "26"                            },
+  { (1u << 26),                        "27"                            },
+  { (1u << 27),                        "28"                            },
+  { (1u << 28),                        "29"                            },
+  { (1u << 29),                        "30"                            },
+  { (1u << 30),                        "31"                            },
+  { (1u << 31),                        "32"                            },
   { CH_PAGE_ANY,               "any"                           },
 
   { -1,                                NULL                            }
@@ -5557,6 +5557,14 @@ editor_elements_info[] =
   }
 };
 
+static struct XY xy_directions[] =
+{
+  { -1,  0 },
+  { +1,  0 },
+  {  0, -1 },
+  {  0, +1 }
+};
+
 
 // ----------------------------------------------------------------------------
 // functions
@@ -10835,13 +10843,7 @@ static int getChipFromOpenDirectionNotEmpty(int direction, int element_old)
 
 static int getClosedTube(int x, int y)
 {
-  static int xy[4][2] =
-  {
-    { -1, 0 },
-    { +1, 0 },
-    { 0, -1 },
-    { 0, +1 }
-  };
+  struct XY *xy = xy_directions;
   int element_old = IntelliDrawBuffer[x][y];
   int direction_old = getOpenDirectionFromTube(element_old);
   int direction_new = MV_NONE;
@@ -10849,8 +10851,8 @@ static int getClosedTube(int x, int y)
 
   for (i = 0; i < NUM_DIRECTIONS; i++)
   {
-    int xx = x + xy[i][0];
-    int yy = y + xy[i][1];
+    int xx = x + xy[i].x;
+    int yy = y + xy[i].y;
     int dir = MV_DIR_FROM_BIT(i);
     int dir_opposite = MV_DIR_OPPOSITE(dir);
 
@@ -10865,13 +10867,7 @@ static int getClosedTube(int x, int y)
 
 static int getClosedBelt(int x, int y)
 {
-  static int xy[4][2] =
-  {
-    { -1, 0 },
-    { +1, 0 },
-    { 0, -1 },
-    { 0, +1 }
-  };
+  struct XY *xy = xy_directions;
   int element_old = IntelliDrawBuffer[x][y];
   int nr = getBeltNrFromBeltElement(element_old);
   int direction_old = getOpenDirectionFromBelt(element_old);
@@ -10880,8 +10876,8 @@ static int getClosedBelt(int x, int y)
 
   for (i = MV_BIT_LEFT; i <= MV_BIT_RIGHT; i++)
   {
-    int xx = x + xy[i][0];
-    int yy = y + xy[i][1];
+    int xx = x + xy[i].x;
+    int yy = y + xy[i].y;
     int dir = MV_DIR_FROM_BIT(i);
     int dir_opposite = MV_DIR_OPPOSITE(dir);
 
@@ -10896,13 +10892,7 @@ static int getClosedBelt(int x, int y)
 
 static int getClosedPool(int x, int y)
 {
-  static int xy[4][2] =
-  {
-    { -1, 0 },
-    { +1, 0 },
-    { 0, -1 },
-    { 0, +1 }
-  };
+  struct XY *xy = xy_directions;
   int element_old = IntelliDrawBuffer[x][y];
   int direction_old = getOpenDirectionFromPool(element_old);
   int direction_new = MV_NONE;
@@ -10910,8 +10900,8 @@ static int getClosedPool(int x, int y)
 
   for (i = 0; i < NUM_DIRECTIONS; i++)
   {
-    int xx = x + xy[i][0];
-    int yy = y + xy[i][1];
+    int xx = x + xy[i].x;
+    int yy = y + xy[i].y;
     int dir = MV_DIR_FROM_BIT(i);
     int dir_opposite = MV_DIR_OPPOSITE(dir);
 
@@ -10927,13 +10917,7 @@ static int getClosedPool(int x, int y)
 
 static int getClosedPillar(int x, int y)
 {
-  static int xy[4][2] =
-  {
-    { -1, 0 },
-    { +1, 0 },
-    { 0, -1 },
-    { 0, +1 }
-  };
+  struct XY *xy = xy_directions;
   int element_old = IntelliDrawBuffer[x][y];
   int direction_old = getOpenDirectionFromPillar(element_old);
   int direction_new = MV_NONE;
@@ -10941,8 +10925,8 @@ static int getClosedPillar(int x, int y)
 
   for (i = MV_BIT_UP; i <= MV_BIT_DOWN; i++)
   {
-    int xx = x + xy[i][0];
-    int yy = y + xy[i][1];
+    int xx = x + xy[i].x;
+    int yy = y + xy[i].y;
     int dir = MV_DIR_FROM_BIT(i);
     int dir_opposite = MV_DIR_OPPOSITE(dir);
 
@@ -10957,13 +10941,7 @@ static int getClosedPillar(int x, int y)
 
 static int getClosedSteel2(int x, int y)
 {
-  static int xy[4][2] =
-  {
-    { -1, 0 },
-    { +1, 0 },
-    { 0, -1 },
-    { 0, +1 }
-  };
+  struct XY *xy = xy_directions;
   int element_old = IntelliDrawBuffer[x][y];
   int direction_old = getOpenDirectionFromSteel2(element_old);
   int direction_new = MV_NONE;
@@ -10971,8 +10949,8 @@ static int getClosedSteel2(int x, int y)
 
   for (i = 0; i < NUM_DIRECTIONS; i++)
   {
-    int xx = x + xy[i][0];
-    int yy = y + xy[i][1];
+    int xx = x + xy[i].x;
+    int yy = y + xy[i].y;
     int dir = MV_DIR_FROM_BIT(i);
     int dir_opposite = MV_DIR_OPPOSITE(dir);
 
@@ -10987,13 +10965,7 @@ static int getClosedSteel2(int x, int y)
 
 static int getClosedChip(int x, int y)
 {
-  static int xy[4][2] =
-  {
-    { -1, 0 },
-    { +1, 0 },
-    { 0, -1 },
-    { 0, +1 }
-  };
+  struct XY *xy = xy_directions;
   int element_old = IntelliDrawBuffer[x][y];
   int direction_old = getOpenDirectionFromChip(element_old);
   int direction_new = MV_NONE;
@@ -11001,8 +10973,8 @@ static int getClosedChip(int x, int y)
 
   for (i = 0; i < NUM_DIRECTIONS; i++)
   {
-    int xx = x + xy[i][0];
-    int yy = y + xy[i][1];
+    int xx = x + xy[i].x;
+    int yy = y + xy[i].y;
     int dir = MV_DIR_FROM_BIT(i);
     int dir_opposite = MV_DIR_OPPOSITE(dir);
 
@@ -11085,13 +11057,7 @@ static void MergeAndCloseNeighbourElements(int x1, int y1, int *element1,
 static void SetElementIntelliDraw(int x, int y, int new_element,
                                  boolean change_level, int button)
 {
-  static int xy[4][2] =
-  {
-    { -1, 0 },
-    { +1, 0 },
-    { 0, -1 },
-    { 0, +1 }
-  };
+  struct XY *xy = xy_directions;
   static int last_x = -1;
   static int last_y = -1;
 
@@ -11117,8 +11083,8 @@ static void SetElementIntelliDraw(int x, int y, int new_element,
 
     for (i = 0; i < NUM_DIRECTIONS; i++)
     {
-      int xx = x + xy[i][0];
-      int yy = y + xy[i][1];
+      int xx = x + xy[i].x;
+      int yy = y + xy[i].y;
 
       if (last_x == xx && last_y == yy && IN_LEV_FIELD(last_x, last_y) &&
          IS_TUBE(IntelliDrawBuffer[last_x][last_y]))
@@ -11155,8 +11121,8 @@ static void SetElementIntelliDraw(int x, int y, int new_element,
 
     for (i = MV_BIT_LEFT; i <= MV_BIT_RIGHT; i++)
     {
-      int xx = x + xy[i][0];
-      int yy = y + xy[i][1];
+      int xx = x + xy[i].x;
+      int yy = y + xy[i].y;
 
       if (last_x == xx && last_y == yy && IN_LEV_FIELD(last_x, last_y) &&
          IS_BELT(IntelliDrawBuffer[last_x][last_y]))
@@ -11193,8 +11159,8 @@ static void SetElementIntelliDraw(int x, int y, int new_element,
 
     for (i = 0; i < NUM_DIRECTIONS; i++)
     {
-      int xx = x + xy[i][0];
-      int yy = y + xy[i][1];
+      int xx = x + xy[i].x;
+      int yy = y + xy[i].y;
 
       if (last_x == xx && last_y == yy && IN_LEV_FIELD(last_x, last_y) &&
          IS_ACID_POOL_OR_ACID(IntelliDrawBuffer[last_x][last_y]))
@@ -11236,8 +11202,8 @@ static void SetElementIntelliDraw(int x, int y, int new_element,
 
     for (i = MV_BIT_UP; i <= MV_BIT_DOWN; i++)
     {
-      int xx = x + xy[i][0];
-      int yy = y + xy[i][1];
+      int xx = x + xy[i].x;
+      int yy = y + xy[i].y;
 
       if (last_x == xx && last_y == yy && IN_LEV_FIELD(last_x, last_y) &&
          IS_EMC_PILLAR(IntelliDrawBuffer[last_x][last_y]))
@@ -11273,8 +11239,8 @@ static void SetElementIntelliDraw(int x, int y, int new_element,
 
     for (i = 0; i < NUM_DIRECTIONS; i++)
     {
-      int xx = x + xy[i][0];
-      int yy = y + xy[i][1];
+      int xx = x + xy[i].x;
+      int yy = y + xy[i].y;
 
       if (last_x == xx && last_y == yy && IN_LEV_FIELD(last_x, last_y) &&
          IS_DC_STEELWALL_2(IntelliDrawBuffer[last_x][last_y]))
@@ -11308,8 +11274,8 @@ static void SetElementIntelliDraw(int x, int y, int new_element,
 
     for (i = 0; i < NUM_DIRECTIONS; i++)
     {
-      int xx = x + xy[i][0];
-      int yy = y + xy[i][1];
+      int xx = x + xy[i].x;
+      int yy = y + xy[i].y;
 
       if (last_x == xx && last_y == yy && IN_LEV_FIELD(last_x, last_y) &&
          IS_SP_CHIP(IntelliDrawBuffer[last_x][last_y]))
@@ -11369,8 +11335,8 @@ static void SetElementIntelliDraw(int x, int y, int new_element,
 
     for (i = 0; i < NUM_DIRECTIONS; i++)
     {
-      int xx = x + xy[i][0];
-      int yy = y + xy[i][1];
+      int xx = x + xy[i].x;
+      int yy = y + xy[i].y;
 
       if (last_x == xx && last_y == yy && IN_LEV_FIELD(last_x, last_y) &&
          IS_IN_GROUP_EL(IntelliDrawBuffer[last_x][last_y], new_element))