coverity check bug fix going over end of array
[mesa.git] / src / mesa / drivers / svga / svgamesa8.c
index 2578428178f3f88fa05c982a2fe94a5e2b6b6312..fd880ef85ad3db442bf36e8328d3bfee53324886 100644 (file)
@@ -1,4 +1,4 @@
-/* $Id: svgamesa8.c,v 1.6 2000/06/14 21:59:07 brianp Exp $ */
+/* $Id: svgamesa8.c,v 1.9 2005/05/04 20:11:39 brianp Exp $ */
 
 /*
  * Mesa 3-D graphics library
@@ -36,6 +36,8 @@
 
 #include "svgapix.h"
 #include "svgamesa8.h"
+#include "swrast/swrast.h"
+
 
 static void __svga_drawpixel8(int x, int y, unsigned long c)
 {
@@ -53,18 +55,13 @@ static unsigned long __svga_getpixel8(int x, int y)
     return SVGABuffer.ReadBuffer[offset];
 }
 
-void __set_index8( GLcontext *ctx, GLuint index )
-{
-   SVGAMesa->index = index;
-}
-
 void __clear_index8( GLcontext *ctx, GLuint index )
 {
    SVGAMesa->clear_index = index;
 }
 
-GLbitfield __clear8( GLcontext *ctx, GLbitfield mask, GLboolean all,
-                     GLint x, GLint y, GLint width, GLint height )
+void __clear8( GLcontext *ctx, GLbitfield mask, GLboolean all,
+               GLint x, GLint y, GLint width, GLint height )
 {
    int i,j;
    
@@ -80,6 +77,7 @@ GLbitfield __clear8( GLcontext *ctx, GLbitfield mask, GLboolean all,
                __svga_drawpixel8(i,j,SVGAMesa->clear_index);
          SVGABuffer.DrawBuffer = tmp;
       }
+      mask &= ~DD_FRONT_LEFT_BIT;
    }
    if (mask & DD_BACK_LEFT_BIT) {
       if (all) { 
@@ -93,11 +91,15 @@ GLbitfield __clear8( GLcontext *ctx, GLbitfield mask, GLboolean all,
                __svga_drawpixel8(i,j,SVGAMesa->clear_index);
          SVGABuffer.DrawBuffer = tmp;
       }
+      mask &= ~DD_BACK_LEFT_BIT;
    }
-   return mask & (~(DD_FRONT_LEFT_BIT | DD_BACK_LEFT_BIT));
+
+   if (mask)
+      _swrast_Clear( ctx, mask, all, x, y, width, height );
 }
 
-void __write_ci32_span8( const GLcontext *ctx, GLuint n, GLint x, GLint y,
+void __write_ci32_span8( const GLcontext *ctx, struct gl_renderbuffer *rb,
+                         GLuint n, GLint x, GLint y,
                          const GLuint index[], const GLubyte mask[] )
 {
    int i;
@@ -108,7 +110,8 @@ void __write_ci32_span8( const GLcontext *ctx, GLuint n, GLint x, GLint y,
    }
 }
 
-void __write_ci8_span8( const GLcontext *ctx, GLuint n, GLint x, GLint y,
+void __write_ci8_span8( const GLcontext *ctx, struct gl_renderbuffer *rb,
+                        GLuint n, GLint x, GLint y,
                         const GLubyte index[], const GLubyte mask[] )
 {
    int i;
@@ -120,18 +123,19 @@ void __write_ci8_span8( const GLcontext *ctx, GLuint n, GLint x, GLint y,
    }
 }
 
-void __write_mono_ci_span8( const GLcontext *ctx, GLuint n,
-                            GLint x, GLint y, const GLubyte mask[] )
+void __write_mono_ci_span8( const GLcontext *ctx, struct gl_renderbuffer *rb,
+                            GLuint n, GLint x, GLint y,
+                            GLuint colorIndex, const GLubyte mask[] )
 {
    int i;
    for (i=0;i<n;i++,x++) {
       if (mask[i]) {
-         __svga_drawpixel8( x, y, SVGAMesa->index);
+         __svga_drawpixel8( x, y, colorIndex);
       }
    }
 }
 
-void __read_ci32_span8( const GLcontext *ctx,
+void __read_ci32_span8( const GLcontext *ctx, struct gl_renderbuffer *rb,
                         GLuint n, GLint x, GLint y, GLuint index[])
 {
    int i;
@@ -140,7 +144,7 @@ void __read_ci32_span8( const GLcontext *ctx,
    }
 }
 
-void __write_ci32_pixels8( const GLcontext *ctx,
+void __write_ci32_pixels8( const GLcontext *ctx, struct gl_renderbuffer *rb,
                            GLuint n, const GLint x[], const GLint y[],
                            const GLuint index[], const GLubyte mask[] )
 {
@@ -153,19 +157,19 @@ void __write_ci32_pixels8( const GLcontext *ctx,
 }
 
 
-void __write_mono_ci_pixels8( const GLcontext *ctx, GLuint n,
-                              const GLint x[], const GLint y[],
-                              const GLubyte mask[] )
+void __write_mono_ci_pixels8( const GLcontext *ctx, struct gl_renderbuffer *rb,
+                              GLuint n, const GLint x[], const GLint y[],
+                              GLuint colorIndex, const GLubyte mask[] )
 {
    int i;
    for (i=0; i<n; i++) {
       if (mask[i]) {
-         __svga_drawpixel8( x[i], y[i], SVGAMesa->index);
+         __svga_drawpixel8( x[i], y[i], colorIndex);
       }
    }
 }
 
-void __read_ci32_pixels8( const GLcontext *ctx,
+void __read_ci32_pixels8( const GLcontext *ctx, struct gl_renderbuffer *rb,
                           GLuint n, const GLint x[], const GLint y[],
                           GLuint index[], const GLubyte mask[] )
 {