Cap array elements at 0 when passed an invalid pointer for an array object.

Otherwise, a pointer greater than the size would underflow and give a large
maximum element.

Reviewed-by: Brian Paul <brianp@vmware.com> (previous version)
This commit is contained in:
Eric Anholt
2009-02-25 11:57:44 -08:00
parent 28471cfa97
commit 058e96916b

View 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.
*/