[Mesa-dev] [PATCH] mesa: check for null ptr in _mesa_is_bufferobj()

Yuanhan Liu yuanhan.liu at linux.intel.com
Wed Nov 23 18:12:59 PST 2011


On Wed, Nov 23, 2011 at 03:35:23PM -0700, Brian Paul wrote:
> This simplifies a few callers.  And it adds a bit of robustness.
> ---
>  src/mesa/main/bufferobj.c        |    6 +++---
>  src/mesa/main/bufferobj.h        |    2 +-
>  src/mesa/state_tracker/st_draw.c |   10 +++++-----
>  3 files changed, 9 insertions(+), 9 deletions(-)

Reviewed-by: Yuanhan Liu <yuanhan.liu at linux.intel.com>

> 
> diff --git a/src/mesa/main/bufferobj.c b/src/mesa/main/bufferobj.c
> index 4c77397..8e8fcd5 100644
> --- a/src/mesa/main/bufferobj.c
> +++ b/src/mesa/main/bufferobj.c
> @@ -1286,14 +1286,14 @@ _mesa_CopyBufferSubData(GLenum readTarget, GLenum writeTarget,
>     ASSERT_OUTSIDE_BEGIN_END(ctx);
>  
>     src = get_buffer(ctx, readTarget);
> -   if (!src || !_mesa_is_bufferobj(src)) {
> +   if (!_mesa_is_bufferobj(src)) {
>        _mesa_error(ctx, GL_INVALID_ENUM,
>                    "glCopyBuffserSubData(readTarget = 0x%x)", readTarget);
>        return;
>     }
>  
>     dst = get_buffer(ctx, writeTarget);
> -   if (!dst || !_mesa_is_bufferobj(dst)) {
> +   if (!_mesa_is_bufferobj(dst)) {
>        _mesa_error(ctx, GL_INVALID_ENUM,
>                    "glCopyBuffserSubData(writeTarget = 0x%x)", writeTarget);
>        return;
> @@ -1421,7 +1421,7 @@ _mesa_MapBufferRange(GLenum target, GLintptr offset, GLsizeiptr length,
>     }
>  
>     bufObj = get_buffer(ctx, target);
> -   if (!bufObj || !_mesa_is_bufferobj(bufObj)) {
> +   if (!_mesa_is_bufferobj(bufObj)) {
>        _mesa_error(ctx, GL_INVALID_ENUM,
>                    "glMapBufferRange(target = 0x%x)", target);
>        return NULL;
> diff --git a/src/mesa/main/bufferobj.h b/src/mesa/main/bufferobj.h
> index b4e70f2..c0d5a64 100644
> --- a/src/mesa/main/bufferobj.h
> +++ b/src/mesa/main/bufferobj.h
> @@ -53,7 +53,7 @@ _mesa_bufferobj_mapped(const struct gl_buffer_object *obj)
>  static inline GLboolean
>  _mesa_is_bufferobj(const struct gl_buffer_object *obj)
>  {
> -   return obj->Name != 0;
> +   return obj != NULL && obj->Name != 0;
>  }
>  
>  
> diff --git a/src/mesa/state_tracker/st_draw.c b/src/mesa/state_tracker/st_draw.c
> index 05a71d3..fd1c8ee 100644
> --- a/src/mesa/state_tracker/st_draw.c
> +++ b/src/mesa/state_tracker/st_draw.c
> @@ -325,7 +325,7 @@ is_interleaved_arrays(const struct st_vertex_program *vp,
>           if (abs(array->Ptr - firstPtr) > firstStride)
>              return GL_FALSE; /* arrays start too far apart */
>  
> -         if ((!bufObj || !_mesa_is_bufferobj(bufObj)) != userSpaceBuffer)
> +         if ((!_mesa_is_bufferobj(bufObj)) != userSpaceBuffer)
>              return GL_FALSE; /* mix of VBO and user-space arrays */
>        }
>     }
> @@ -390,7 +390,7 @@ setup_interleaved_attribs(struct gl_context *ctx,
>     }
>  
>     /* are the arrays in user space? */
> -   usingVBO = bufobj && _mesa_is_bufferobj(bufobj);
> +   usingVBO = _mesa_is_bufferobj(bufobj);
>  
>     for (attr = 0; attr < vpv->num_inputs; attr++) {
>        const GLuint mesaAttr = vp->index_to_input[attr];
> @@ -497,7 +497,7 @@ setup_non_interleaved_attribs(struct gl_context *ctx,
>  
>        assert(element_size == array->Size * _mesa_sizeof_type(array->Type));
>  
> -      if (bufobj && _mesa_is_bufferobj(bufobj)) {
> +      if (_mesa_is_bufferobj(bufobj)) {
>           /* Attribute data is in a VBO.
>            * Recall that for VBOs, the gl_client_array->Ptr field is
>            * really an offset from the start of the VBO, not a pointer.
> @@ -599,7 +599,7 @@ setup_index_buffer(struct gl_context *ctx,
>        }
>  
>        /* get/create the index buffer object */
> -      if (bufobj && _mesa_is_bufferobj(bufobj)) {
> +      if (_mesa_is_bufferobj(bufobj)) {
>           /* elements/indexes are in a real VBO */
>           struct st_buffer_object *stobj = st_buffer_object(bufobj);
>           pipe_resource_reference(&ibuffer->buffer, stobj->buffer);
> @@ -775,7 +775,7 @@ handle_fallback_primitive_restart(struct pipe_context *pipe,
>     info.primitive_restart = FALSE;
>     info.instance_count = 1;
>  
> -   if (ib->obj && _mesa_is_bufferobj(ib->obj)) {
> +   if (_mesa_is_bufferobj(ib->obj)) {
>        ptr = pipe_buffer_map_range(pipe, ibuffer->buffer,
>                                    start * ibuffer->index_size, /* start */
>                                    count * ibuffer->index_size, /* length */
> -- 
> 1.7.3.4
> 
> _______________________________________________
> mesa-dev mailing list
> mesa-dev at lists.freedesktop.org
> http://lists.freedesktop.org/mailman/listinfo/mesa-dev


More information about the mesa-dev mailing list