[Mesa-dev] [PATCH] mesa: take into account indices offset for bounds check
Eric Anholt
eric at anholt.net
Wed Oct 12 10:13:06 PDT 2011
On Sat, 24 Sep 2011 13:08:43 +0400, Vadim Girlin <vadimgirlin at gmail.com> wrote:
> ---
> src/mesa/main/api_validate.c | 9 ++++++---
> 1 files changed, 6 insertions(+), 3 deletions(-)
>
> diff --git a/src/mesa/main/api_validate.c b/src/mesa/main/api_validate.c
> index 1fcf5cd..9338f4c 100644
> --- a/src/mesa/main/api_validate.c
> +++ b/src/mesa/main/api_validate.c
> @@ -257,7 +257,8 @@ _mesa_validate_DrawElements(struct gl_context *ctx,
> if (_mesa_is_bufferobj(ctx->Array.ElementArrayBufferObj)) {
> /* use indices in the buffer object */
> /* make sure count doesn't go outside buffer bounds */
> - if (index_bytes(type, count) > ctx->Array.ElementArrayBufferObj->Size) {
> + GLbyte * indices_end = (GLbyte*)indices + index_bytes(type, count);
> + if (indices_end > (GLbyte*)ctx->Array.ElementArrayBufferObj->Size) {
> _mesa_warning(ctx, "glDrawElements index out of buffer bounds");
> return GL_FALSE;
> }
> @@ -318,7 +319,8 @@ _mesa_validate_DrawRangeElements(struct gl_context *ctx, GLenum mode,
> if (_mesa_is_bufferobj(ctx->Array.ElementArrayBufferObj)) {
> /* use indices in the buffer object */
> /* make sure count doesn't go outside buffer bounds */
> - if (index_bytes(type, count) > ctx->Array.ElementArrayBufferObj->Size) {
> + GLbyte * indices_end = (GLbyte*)indices + index_bytes(type, count);
> + if (indices_end > (GLbyte*)ctx->Array.ElementArrayBufferObj->Size) {
> _mesa_warning(ctx, "glDrawRangeElements index out of buffer bounds");
> return GL_FALSE;
> }
> @@ -457,7 +459,8 @@ _mesa_validate_DrawElementsInstanced(struct gl_context *ctx,
> if (_mesa_is_bufferobj(ctx->Array.ElementArrayBufferObj)) {
> /* use indices in the buffer object */
> /* make sure count doesn't go outside buffer bounds */
> - if (index_bytes(type, count) > ctx->Array.ElementArrayBufferObj->Size) {
> + GLbyte * indices_end = (GLbyte*)indices + index_bytes(type, count);
> + if (indices_end > (GLbyte*)ctx->Array.ElementArrayBufferObj->Size) {
> _mesa_warning(ctx,
> "glDrawElementsInstanced index out of buffer bounds");
> return GL_FALSE;
This index buffer checking really looks like it should be in a separate
helper function.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 197 bytes
Desc: not available
URL: <http://lists.freedesktop.org/archives/mesa-dev/attachments/20111012/4e979874/attachment.pgp>
More information about the mesa-dev
mailing list