Cap array elements at 0 when passed an invalid pointer for an array object.
authorEric Anholt <eric@anholt.net>
Wed, 25 Feb 2009 19:57:44 +0000 (11:57 -0800)
committerEric Anholt <eric@anholt.net>
Tue, 7 Jul 2009 22:16:28 +0000 (15:16 -0700)
Otherwise, a pointer greater than the size would underflow and give a large
maximum element.

Reviewed-by: Brian Paul <brianp@vmware.com> (previous version)
src/mesa/main/state.c

index 7b41b8f4da479f862518eeaae04633bc83b0250c..3b2c6ec6189d2d68b41a2096345aae0d04dac0b2 100644 (file)
@@ -75,6 +75,16 @@ compute_max_element(struct gl_client_array *array)
 {
    assert(array->Enabled);
    if (array->BufferObj->Name) {
+      GLsizeiptrARB offset = (GLsizeiptrARB) array->Ptr;
+      GLsizeiptrARB obj_size = (GLsizeiptrARB) array->BufferObj->Size;
+
+      if (offset < obj_size) {
+        array->_MaxElement = (obj_size - offset +
+                              array->StrideB -
+                              array->_ElementSize) / array->StrideB;
+      } else {
+        array->_MaxElement = 0;
+      }
       /* Compute the max element we can access in the VBO without going
        * out of bounds.
        */