[AD] Proposed pedantic asserts

[ Thread Index | Date Index | More lists.liballeg.org/allegro-developers Archives ]


Attached proposed patch with pedantic asserts.
Index: src/gfx.c
===================================================================
RCS file: /cvsroot/alleg/allegro/src/gfx.c,v
retrieving revision 1.19
diff -u -r1.19 gfx.c
--- src/gfx.c	16 Oct 2004 19:45:31 -0000	1.19
+++ src/gfx.c	6 Dec 2004 22:30:27 -0000
@@ -181,6 +181,7 @@
  */
 void set_color(int index, AL_CONST RGB *p)
 {
+   ASSERT(index >= 0 && index < PAL_SIZE);
    set_palette_range((struct RGB *)p-index, index, index, FALSE);
 }
 
@@ -203,6 +204,9 @@
 {
    int c;
 
+   ASSERT(from >= 0 && from < PAL_SIZE);
+   ASSERT(to >= 0 && to < PAL_SIZE)
+
    for (c=from; c<=to; c++) {
       _current_palette[c] = p[c];
 
@@ -225,7 +229,7 @@
 /* previous palette, so the image loaders can restore it when they are done */
 int _got_prev_current_palette = FALSE;
 PALETTE _prev_current_palette;
-static int prev_palette_color[256];
+static int prev_palette_color[PAL_SIZE];
 
 
 
@@ -239,13 +243,13 @@
 {
    int c;
 
-   for (c=0; c<256; c++) {
+   for (c=0; c<PAL_SIZE; c++) {
       _prev_current_palette[c] = _current_palette[c];
       _current_palette[c] = p[c];
    }
 
    if (_color_depth != 8) {
-      for (c=0; c<256; c++) {
+      for (c=0; c<PAL_SIZE; c++) {
 	 prev_palette_color[c] = palette_color[c];
 	 palette_color[c] = makecol(_rgb_scale_6[p[c].r], _rgb_scale_6[p[c].g], _rgb_scale_6[p[c].b]);
       }
@@ -265,11 +269,11 @@
 {
    int c;
 
-   for (c=0; c<256; c++)
+   for (c=0; c<PAL_SIZE; c++)
       _current_palette[c] = _prev_current_palette[c];
 
    if (_color_depth != 8) {
-      for (c=0; c<256; c++)
+      for (c=0; c<PAL_SIZE; c++)
 	 palette_color[c] = prev_palette_color[c];
    }
 
@@ -297,7 +301,7 @@
    }
 
    if (_current_palette_changed & (1<<(bpp-1))) {
-      for (c=0; c<256; c++) {
+      for (c=0; c<PAL_SIZE; c++) {
 	 table[c] = makecol_depth(bpp,
 				  _rgb_scale_6[_current_palette[c].r], 
 				  _rgb_scale_6[_current_palette[c].g], 
@@ -325,7 +329,7 @@
 {
    int c;
 
-   for (c=0; c<256; c++) {
+   for (c=0; c<PAL_SIZE; c++) {
       pal[c].r = ((c>>5)&7) * 63/7;
       pal[c].g = ((c>>2)&7) * 63/7;
       pal[c].b = (c&3) * 63/3;
@@ -345,6 +349,8 @@
  */
 void get_color(int index, RGB *p)
 {
+   ASSERT(index >= 0 && index < PAL_SIZE);
+   ASSERT(p);
    get_palette_range(p-index, index, index);
 }
 
@@ -367,6 +373,9 @@
 {
    int c;
 
+   ASSERT(from >= 0 && from < PAL_SIZE);
+   ASSERT(to >= 0 && to < PAL_SIZE);
+
    if ((system_driver) && (system_driver->read_hardware_palette))
       system_driver->read_hardware_palette();
 
@@ -386,6 +395,10 @@
 {
    int c;
 
+   ASSERT(pos >= 0 && pos <= 64);
+   ASSERT(from >= 0 && from < PAL_SIZE);
+   ASSERT(to >= 0 && to < PAL_SIZE);
+
    for (c=from; c<=to; c++) { 
       output[c].r = ((int)source[c].r * (63-pos) + (int)dest[c].r * pos) / 64;
       output[c].g = ((int)source[c].g * (63-pos) + (int)dest[c].g * pos) / 64;
@@ -405,6 +418,10 @@
    PALETTE temp;
    int c, start, last;
 
+   ASSERT(speed > 0 && speed <= 64);
+   ASSERT(from >= 0 && from < PAL_SIZE);
+   ASSERT(to >= 0 && to < PAL_SIZE);
+
    for (c=0; c<PAL_SIZE; c++)
       temp[c] = source[c];
 
@@ -440,6 +457,9 @@
  */
 void fade_in_range(AL_CONST PALETTE p, int speed, int from, int to)
 {
+   ASSERT(speed > 0 && speed <= 64);
+   ASSERT(from >= 0 && from < PAL_SIZE);
+   ASSERT(to >= 0 && to < PAL_SIZE);
    fade_from_range(black_palette, p, speed, from, to);
 }
 
@@ -454,6 +474,9 @@
 void fade_out_range(int speed, int from, int to)
 {
    PALETTE temp;
+   ASSERT(speed > 0 && speed <= 64);
+   ASSERT(from >= 0 && from < PAL_SIZE);
+   ASSERT(to >= 0 && to < PAL_SIZE);
 
    get_palette(temp);
    fade_from_range(temp, black_palette, speed, from, to);
@@ -467,6 +490,7 @@
  */
 void fade_from(AL_CONST PALETTE source, AL_CONST PALETTE dest, int speed)
 {
+   ASSERT(speed > 0 && speed <= 64);
    fade_from_range(source, dest, speed, 0, PAL_SIZE-1);
 }
 
@@ -478,6 +502,7 @@
  */
 void fade_in(AL_CONST PALETTE p, int speed)
 {
+   ASSERT(speed > 0 && speed <= 64);
    fade_in_range(p, speed, 0, PAL_SIZE-1);
 }
 
@@ -489,6 +514,7 @@
  */
 void fade_out(int speed)
 {
+   ASSERT(speed > 0 && speed <= 64);
    fade_out_range(speed, 0, PAL_SIZE-1);
 }
 


Mail converted by MHonArc 2.6.19+ http://listengine.tuxfamily.org/