tnl: Don't dereference NULL obj pointer in bind_indices
authorIan Romanick <ian.d.romanick@intel.com>
Wed, 8 Apr 2020 03:19:41 +0000 (20:19 -0700)
committerIan Romanick <ian.d.romanick@intel.com>
Mon, 13 Apr 2020 17:26:38 +0000 (10:26 -0700)
Structurally the code is now similar to bind_inputs.  The fixes tag is a
little bit misleading.  I think the change in that commit just exposes a
previously existing bug.

Closes: https://gitlab.freedesktop.org/mesa/mesa/-/issues/2746
Fixes: f3cce7087a5 ("mesa: don't ever bind NullBufferObj for glBindBuffer targets")
Reviewed-by: Marek Olšák <marek.olsak@amd.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/4512>

src/mesa/tnl/t_draw.c

index 335161ef0d0388cc22ba2022e4873aa1ef34309f..2146fe92c8829577d48e7ef1fba2dbd811fea3aa 100644 (file)
@@ -362,20 +362,22 @@ static void bind_indices( struct gl_context *ctx,
       return;
    }
 
-   if (ib->obj &&
-       !_mesa_bufferobj_mapped(ib->obj, MAP_INTERNAL)) {
-      /* if the buffer object isn't mapped yet, map it now */
-      bo[*nr_bo] = ib->obj;
-      (*nr_bo)++;
-      ptr = ctx->Driver.MapBufferRange(ctx, (GLsizeiptr) ib->ptr,
-                                       ib->count << ib->index_size_shift,
-                                      GL_MAP_READ_BIT, ib->obj,
-                                       MAP_INTERNAL);
-      assert(ib->obj->Mappings[MAP_INTERNAL].Pointer);
-   } else {
-      /* user-space elements, or buffer already mapped */
-      ptr = ADD_POINTERS(ib->obj->Mappings[MAP_INTERNAL].Pointer, ib->ptr);
-   }
+   if (ib->obj) {
+      if (!_mesa_bufferobj_mapped(ib->obj, MAP_INTERNAL)) {
+         /* if the buffer object isn't mapped yet, map it now */
+         bo[*nr_bo] = ib->obj;
+         (*nr_bo)++;
+         ptr = ctx->Driver.MapBufferRange(ctx, (GLsizeiptr) ib->ptr,
+                                          ib->count << ib->index_size_shift,
+                                          GL_MAP_READ_BIT, ib->obj,
+                                          MAP_INTERNAL);
+         assert(ib->obj->Mappings[MAP_INTERNAL].Pointer);
+      } else {
+         /* user-space elements, or buffer already mapped */
+         ptr = ADD_POINTERS(ib->obj->Mappings[MAP_INTERNAL].Pointer, ib->ptr);
+      }
+   } else
+      ptr = ib->ptr;
 
    if (ib->index_size_shift == 2 && VB->Primitive[0].basevertex == 0) {
       VB->Elts = (GLuint *) ptr;