fix for-loop in _mesa_GetDouble to avoid out of bounds memory read
[mesa.git] / src / mesa / main / drawpix.c
index b9b472492b0875fba5106b7d0b9b561cf15567f8..6f7cae9ef5578ba91e23c5851a18ec53596e1962 100644 (file)
@@ -1,9 +1,8 @@
-
 /*
  * Mesa 3-D graphics library
- * Version:  4.1
+ * Version:  6.1
  *
- * Copyright (C) 1999-2002  Brian Paul   All Rights Reserved.
+ * Copyright (C) 1999-2004  Brian Paul   All Rights Reserved.
  *
  * Permission is hereby granted, free of charge, to any person obtaining a
  * copy of this software and associated documentation files (the "Software"),
 #include "state.h"
 #include "mtypes.h"
 
+
 #if _HAVE_FULL_GL
 
 /*
  * Execute glDrawPixels
  */
-void
+void GLAPIENTRY
 _mesa_DrawPixels( GLsizei width, GLsizei height,
                   GLenum format, GLenum type, const GLvoid *pixels )
 {
    GET_CURRENT_CONTEXT(ctx);
    ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx);
 
+   if (ctx->FragmentProgram.Enabled && !ctx->FragmentProgram._Enabled) {
+      _mesa_error(ctx, GL_INVALID_OPERATION,
+                  "glDrawPixels (invalid fragment program)");
+      return;
+   }
+
    if (width < 0 || height < 0) {
       _mesa_error( ctx, GL_INVALID_VALUE, "glDrawPixels(width or height < 0" );
       return;
@@ -52,7 +58,7 @@ _mesa_DrawPixels( GLsizei width, GLsizei height,
 
    if (ctx->RenderMode==GL_RENDER) {
       GLint x, y;
-      if (!pixels || !ctx->Current.RasterPosValid) {
+      if (!ctx->Current.RasterPosValid) {
         return;
       }
 
@@ -87,7 +93,8 @@ _mesa_DrawPixels( GLsizei width, GLsizei height,
    }
 }
 
-void
+
+void GLAPIENTRY
 _mesa_CopyPixels( GLint srcx, GLint srcy, GLsizei width, GLsizei height,
                   GLenum type )
 {
@@ -95,6 +102,12 @@ _mesa_CopyPixels( GLint srcx, GLint srcy, GLsizei width, GLsizei height,
    GLint destx, desty;
    ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx);
 
+   if (ctx->FragmentProgram.Enabled && !ctx->FragmentProgram._Enabled) {
+      _mesa_error(ctx, GL_INVALID_OPERATION,
+                  "glCopyPixels (invalid fragment program)");
+      return;
+   }
+
    if (width < 0 || height < 0) {
       _mesa_error( ctx, GL_INVALID_VALUE, "glCopyPixels(width or height < 0)" );
       return;
@@ -135,11 +148,11 @@ _mesa_CopyPixels( GLint srcx, GLint srcy, GLsizei width, GLsizei height,
    }
 }
 
-#endif
+#endif /* _HAVE_FULL_GL */
 
 
 
-void
+void GLAPIENTRY
 _mesa_ReadPixels( GLint x, GLint y, GLsizei width, GLsizei height,
                  GLenum format, GLenum type, GLvoid *pixels )
 {
@@ -152,11 +165,6 @@ _mesa_ReadPixels( GLint x, GLint y, GLsizei width, GLsizei height,
       return;
    }
 
-   if (!pixels) {
-      _mesa_error( ctx, GL_INVALID_VALUE, "glReadPixels(pixels)" );
-      return;
-   }
-
    if (ctx->NewState)
       _mesa_update_state(ctx);
 
@@ -166,9 +174,7 @@ _mesa_ReadPixels( GLint x, GLint y, GLsizei width, GLsizei height,
 
 
 
-
-
-void
+void GLAPIENTRY
 _mesa_Bitmap( GLsizei width, GLsizei height,
               GLfloat xorig, GLfloat yorig, GLfloat xmove, GLfloat ymove,
               const GLubyte *bitmap )
@@ -176,6 +182,12 @@ _mesa_Bitmap( GLsizei width, GLsizei height,
    GET_CURRENT_CONTEXT(ctx);
    ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx);
 
+   if (ctx->FragmentProgram.Enabled && !ctx->FragmentProgram._Enabled) {
+      _mesa_error(ctx, GL_INVALID_OPERATION,
+                  "glBitmap (invalid fragment program)");
+      return;
+   }
+
    if (width < 0 || height < 0) {
       _mesa_error( ctx, GL_INVALID_VALUE, "glBitmap(width or height < 0)" );
       return;
@@ -186,18 +198,16 @@ _mesa_Bitmap( GLsizei width, GLsizei height,
    }
 
    if (ctx->RenderMode==GL_RENDER) {
-      if (bitmap) {
-         /* Truncate, to satisfy conformance tests (matches SGI's OpenGL). */
-         GLint x = IFLOOR(ctx->Current.RasterPos[0] - xorig);
-         GLint y = IFLOOR(ctx->Current.RasterPos[1] - yorig);
-
-         if (ctx->NewState) {
-            _mesa_update_state(ctx);
-         }
+      /* Truncate, to satisfy conformance tests (matches SGI's OpenGL). */
+      GLint x = IFLOOR(ctx->Current.RasterPos[0] - xorig);
+      GLint y = IFLOOR(ctx->Current.RasterPos[1] - yorig);
 
-         ctx->OcclusionResult = GL_TRUE;
-        ctx->Driver.Bitmap( ctx, x, y, width, height, &ctx->Unpack, bitmap );
+      if (ctx->NewState) {
+         _mesa_update_state(ctx);
       }
+
+      ctx->OcclusionResult = GL_TRUE;
+      ctx->Driver.Bitmap( ctx, x, y, width, height, &ctx->Unpack, bitmap );
    }
 #if _HAVE_FULL_GL
    else if (ctx->RenderMode==GL_FEEDBACK) {
@@ -232,7 +242,7 @@ _mesa_Bitmap( GLsizei width, GLsizei height,
  * Z-compositing.  Normally, this operation requires two glDrawPixels
  * calls with stencil testing.
  */
-void
+void GLAPIENTRY
 _mesa_DrawDepthPixelsMESA( GLsizei width, GLsizei height,
                            GLenum colorFormat, GLenum colorType,
                            const GLvoid *colors,