[Mesa-dev] [PATCH 2/4] mesa/image: assert on bad format

nobled nobled at dreamwidth.org
Wed Oct 19 05:02:46 PDT 2011


NULL as an error indicator is meaningless, since it will return NULL
on success anyway if the caller passes in zero as the image's address
and asks to calculate the offset of the first pixel. For example,
_mesa_validate_pbo_access() does this.

This also matches the code in the non-GL_BITMAP codepath, which
already has an assert like this.
---
 src/mesa/main/image.c |   16 ++++++++--------
 1 files changed, 8 insertions(+), 8 deletions(-)

diff --git a/src/mesa/main/image.c b/src/mesa/main/image.c
index ca5771c..3e0ca05 100644
--- a/src/mesa/main/image.c
+++ b/src/mesa/main/image.c
@@ -1093,17 +1093,17 @@ _mesa_is_compressed_format(struct gl_context
*ctx, GLenum format)
  * Pixel unpacking/packing parameters are observed according to \p packing.
  *
  * \param dimensions either 1, 2 or 3 to indicate dimensionality of image
+ * \param packing  the pixelstore attributes
  * \param image  starting address of image data
  * \param width  the image width
- * \param height  theimage height
- * \param format  the pixel format
- * \param type  the pixel data type
- * \param packing  the pixelstore attributes
+ * \param height  the image height
+ * \param format  the pixel format (must be validated beforehand)
+ * \param type  the pixel data type (must be validated beforehand)
  * \param img  which image in the volume (0 for 1D or 2D images)
  * \param row  row of pixel in the image (0 for 1D images)
  * \param column column of pixel in the image
  *
- * \return address of pixel on success, or NULL on error.
+ * \return address of pixel.
  *
  * \sa gl_pixelstore_attrib.
  */
@@ -1153,9 +1153,9 @@ _mesa_image_address( GLuint dimensions,

       /* Compute number of components per pixel */
       comp_per_pixel = _mesa_components_in_format( format );
-      if (comp_per_pixel < 0) {
-         return NULL;
-      }
+
+      /* The pixel type and format should have been error checked earlier */
+      assert(comp_per_pixel > 0);

       bytes_per_row = alignment
                     * CEILING( comp_per_pixel*pixels_per_row, 8*alignment );
-- 
1.7.6.msysgit.0
-------------- next part --------------
From adb592410ca506107b5294222eadd84c35584ed5 Mon Sep 17 00:00:00 2001
From: nobled <nobled at dreamwidth.org>
Date: Mon, 17 Oct 2011 21:34:44 +0000
Subject: [PATCH 2/4] mesa/image: assert on bad format

NULL as an error indicator is meaningless, since it will return NULL
on success anyway if the caller passes in zero as the image's address
and asks to calculate the offset of the first pixel. For example,
_mesa_validate_pbo_access() does this.

This also matches the code in the non-GL_BITMAP codepath, which
already has an assert like this.
---
 src/mesa/main/image.c |   16 ++++++++--------
 1 files changed, 8 insertions(+), 8 deletions(-)

diff --git a/src/mesa/main/image.c b/src/mesa/main/image.c
index ca5771c..3e0ca05 100644
--- a/src/mesa/main/image.c
+++ b/src/mesa/main/image.c
@@ -1093,17 +1093,17 @@ _mesa_is_compressed_format(struct gl_context *ctx, GLenum format)
  * Pixel unpacking/packing parameters are observed according to \p packing.
  *
  * \param dimensions either 1, 2 or 3 to indicate dimensionality of image
+ * \param packing  the pixelstore attributes
  * \param image  starting address of image data
  * \param width  the image width
- * \param height  theimage height
- * \param format  the pixel format
- * \param type  the pixel data type
- * \param packing  the pixelstore attributes
+ * \param height  the image height
+ * \param format  the pixel format (must be validated beforehand)
+ * \param type  the pixel data type (must be validated beforehand)
  * \param img  which image in the volume (0 for 1D or 2D images)
  * \param row  row of pixel in the image (0 for 1D images)
  * \param column column of pixel in the image
  * 
- * \return address of pixel on success, or NULL on error.
+ * \return address of pixel.
  *
  * \sa gl_pixelstore_attrib.
  */
@@ -1153,9 +1153,9 @@ _mesa_image_address( GLuint dimensions,
 
       /* Compute number of components per pixel */
       comp_per_pixel = _mesa_components_in_format( format );
-      if (comp_per_pixel < 0) {
-         return NULL;
-      }
+
+      /* The pixel type and format should have been error checked earlier */
+      assert(comp_per_pixel > 0);
 
       bytes_per_row = alignment
                     * CEILING( comp_per_pixel*pixels_per_row, 8*alignment );
-- 
1.7.6.msysgit.0



More information about the mesa-dev mailing list