coverity check bug fix going over end of array
[mesa.git] / src / mesa / drivers / svga / svgamesa8.c
index 048ad98859746e721c2e55f6e33d8625f9841134..fd880ef85ad3db442bf36e8328d3bfee53324886 100644 (file)
@@ -1,4 +1,4 @@
-/* $Id: svgamesa8.c,v 1.4 2000/01/25 00:03:02 brianp Exp $ */
+/* $Id: svgamesa8.c,v 1.9 2005/05/04 20:11:39 brianp Exp $ */
 
 /*
  * Mesa 3-D graphics library
  * Additional authors:  Slawomir Szczyrba <steev@hot.pl>  (Mesa 3.2)
  */
 
+#ifdef HAVE_CONFIG_H
+#include "conf.h"
+#endif
+
 #ifdef SVGA
 
 
 #include "svgapix.h"
 #include "svgamesa8.h"
+#include "swrast/swrast.h"
+
 
 static void __svga_drawpixel8(int x, int y, unsigned long c)
 {
@@ -49,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;
    
@@ -76,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) { 
@@ -89,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;
@@ -104,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;
@@ -116,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;
@@ -136,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[] )
 {
@@ -149,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[] )
 {
@@ -172,4 +180,14 @@ void __read_ci32_pixels8( const GLcontext *ctx,
 }
 
 
+#else
+
+
+/* silence compiler warning */
+extern void _mesa_svga8_dummy_function(void);
+void _mesa_svga8_dummy_function(void)
+{
+}
+
+
 #endif