[AD] Adding some asserts

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


Proposed patch attached.
Index: src/color.c
===================================================================
RCS file: /cvsroot/alleg/allegro/src/color.c,v
retrieving revision 1.20
diff -u -p -r1.20 color.c
--- src/color.c	19 Jun 2003 06:51:58 -0000	1.20
+++ src/color.c	11 May 2005 15:36:44 -0000
@@ -290,6 +290,10 @@ int bestfit_color(AL_CONST PALETTE pal, 
 {
    int i, coldiff, lowest, bestfit;
 
+   ASSERT(r >= 0 && r <= 63);
+   ASSERT(g >= 0 && g <= 63);
+   ASSERT(b >= 0 && b <= 63);
+
    if (col_diff[1] == 0)
       bestfit_init();
 
@@ -348,6 +352,10 @@ void hsv_to_rgb(float h, float s, float 
    float f, x, y, z;
    int i;
 
+   ASSERT(h >= 0 && h <= 360);
+   ASSERT(s >= 0 && s <= 1);
+   ASSERT(v >= 0 && v <= 1);
+
    v *= 255.0f;
 
    if (s == 0.0f) { /* ok since we don't divide by s, and faster */
@@ -416,6 +424,10 @@ void rgb_to_hsv(int r, int g, int b, flo
 {
    int delta;
 
+   ASSERT(r >= 0 && r <= 255);
+   ASSERT(g >= 0 && g <= 255);
+   ASSERT(b >= 0 && b <= 255);
+
    if (r > g) {
       if (b > r) {
 	 /* b>r>g */
@@ -667,6 +679,11 @@ void create_light_table(COLOR_MAP *table
    int r1, g1, b1, r2, g2, b2, x, y;
    unsigned int t1, t2;
 
+   ASSERT(table);
+   ASSERT(r >= 0 && r <= 63);
+   ASSERT(g >= 0 && g <= 63);
+   ASSERT(b >= 0 && b <= 63);
+
    if (rgb_map) {
       for (x=0; x<PAL_SIZE-1; x++) {
 	 t1 = x * 0x010101;
@@ -732,6 +749,11 @@ void create_trans_table(COLOR_MAP *table
    int tr, tg, tb;
    int add;
 
+   ASSERT(table);
+   ASSERT(r >= 0 && r <= 255);
+   ASSERT(g >= 0 && g <= 255);
+   ASSERT(b >= 0 && b <= 255);
+
    /* This is a bit ugly, but accounts for the solidity parameters
       being in the range 0-255 rather than 0-256. Given that the
       precision of r,g,b components is only 6 bits it shouldn't do any


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