Mesa (master): mesa: do error checking on glCopyPixels() type parameter

Brian Paul brianp at kemper.freedesktop.org
Fri Aug 7 15:52:19 UTC 2009


Module: Mesa
Branch: master
Commit: 3335b847bf1e1ee9e77600bd7122eb56ffbc8c07
URL:    http://cgit.freedesktop.org/mesa/mesa/commit/?id=3335b847bf1e1ee9e77600bd7122eb56ffbc8c07

Author: Brian Paul <brianp at vmware.com>
Date:   Fri Aug  7 09:03:49 2009 -0600

mesa: do error checking on glCopyPixels() type parameter

Plus, move some other error checks before state validation and update
some comments.

---

 src/mesa/main/drawpix.c |   23 +++++++++++++++--------
 1 files changed, 15 insertions(+), 8 deletions(-)

diff --git a/src/mesa/main/drawpix.c b/src/mesa/main/drawpix.c
index 6682b5e..ec8a45c 100644
--- a/src/mesa/main/drawpix.c
+++ b/src/mesa/main/drawpix.c
@@ -27,6 +27,7 @@
 #include "bufferobj.h"
 #include "context.h"
 #include "drawpix.h"
+#include "enums.h"
 #include "feedback.h"
 #include "framebuffer.h"
 #include "image.h"
@@ -62,7 +63,7 @@ _mesa_DrawPixels( GLsizei width, GLsizei height,
    }
 
    if (_mesa_error_check_format_type(ctx, format, type, GL_TRUE)) {
-      /* found an error */
+      /* the error was already recorded */
       return;
    }
 
@@ -73,7 +74,7 @@ _mesa_DrawPixels( GLsizei width, GLsizei height,
    }
 
    if (!ctx->Current.RasterPosValid) {
-      return;
+      return; /* no-op, not an error */
    }
 
    if (ctx->RenderMode == GL_RENDER) {
@@ -126,6 +127,17 @@ _mesa_CopyPixels( GLint srcx, GLint srcy, GLsizei width, GLsizei height,
    GET_CURRENT_CONTEXT(ctx);
    ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx);
 
+   if (width < 0 || height < 0) {
+      _mesa_error(ctx, GL_INVALID_VALUE, "glCopyPixels(width or height < 0)");
+      return;
+   }
+
+   if (type != GL_COLOR && type != GL_DEPTH && type != GL_STENCIL) {
+      _mesa_error(ctx, GL_INVALID_ENUM, "glCopyPixels(type=%s)",
+                  _mesa_lookup_enum_by_nr(type));
+      return;
+   }
+
    if (ctx->NewState) {
       _mesa_update_state(ctx);
    }
@@ -136,11 +148,6 @@ _mesa_CopyPixels( GLint srcx, GLint srcy, GLsizei width, GLsizei height,
       return;
    }
 
-   if (width < 0 || height < 0) {
-      _mesa_error(ctx, GL_INVALID_VALUE, "glCopyPixels(width or height < 0)");
-      return;
-   }
-
    if (ctx->DrawBuffer->_Status != GL_FRAMEBUFFER_COMPLETE_EXT ||
        ctx->ReadBuffer->_Status != GL_FRAMEBUFFER_COMPLETE_EXT) {
       _mesa_error(ctx, GL_INVALID_FRAMEBUFFER_OPERATION_EXT,
@@ -156,7 +163,7 @@ _mesa_CopyPixels( GLint srcx, GLint srcy, GLsizei width, GLsizei height,
    }
 
    if (!ctx->Current.RasterPosValid || width ==0 || height == 0) {
-      return;
+      return; /* no-op, not an error */
    }
 
    if (ctx->RenderMode == GL_RENDER) {




More information about the mesa-commit mailing list