mesa: add extra null checks in vbo_rebase_prims()
authorJuha-Pekka Heikkila <juhapekka.heikkila@gmail.com>
Sun, 27 Apr 2014 20:04:58 +0000 (23:04 +0300)
committerIan Romanick <ian.d.romanick@intel.com>
Fri, 2 May 2014 19:00:30 +0000 (12:00 -0700)
v2 [idr]: Move declarations before code to prevent MSVC build breaks.

Signed-off-by: Juha-Pekka Heikkila <juhapekka.heikkila@gmail.com>
Reviewed-by: Matt Turner <mattst88@gmail.com>
Signed-off-by: Ian Romanick <ian.d.romanick@intel.com>
src/mesa/vbo/vbo_rebase.c

index f3fe5f75708d97b1c6da3e8acdaa788bfc954364..82a0b8e2b9d4e83c8f897c239503b41790dea3ad 100644 (file)
@@ -58,9 +58,14 @@ static void *rebase_##TYPE( const void *ptr,                 \
                          GLuint count,                         \
                          TYPE min_index )                      \
 {                                                              \
-   const TYPE *in = (TYPE *)ptr;                               \
-   TYPE *tmp_indices = malloc(count * sizeof(TYPE));   \
    GLuint i;                                                   \
+   const TYPE *in = (TYPE *)ptr;                               \
+   TYPE *tmp_indices = malloc(count * sizeof(TYPE));           \
+                                                               \
+   if (tmp_indices == NULL) {                                   \
+      _mesa_error_no_memory(__func__);                          \
+      return NULL;                                              \
+   }                                                            \
                                                                \
    for (i = 0; i < count; i++)                                 \
       tmp_indices[i] = in[i] - min_index;                      \
@@ -148,6 +153,11 @@ void vbo_rebase_prims( struct gl_context *ctx,
        */
       tmp_prims = malloc(sizeof(*prim) * nr_prims);
 
+      if (tmp_prims == NULL) {
+         _mesa_error_no_memory(__func__);
+         return;
+      }
+
       for (i = 0; i < nr_prims; i++) {
         tmp_prims[i] = prim[i];
         tmp_prims[i].basevertex -= min_index;
@@ -186,6 +196,10 @@ void vbo_rebase_prims( struct gl_context *ctx,
       if (map_ib) 
         ctx->Driver.UnmapBuffer(ctx, ib->obj, MAP_INTERNAL);
 
+      if (tmp_indices == NULL) {
+         return;
+      }
+
       tmp_ib.obj = ctx->Shared->NullBufferObj;
       tmp_ib.ptr = tmp_indices;
       tmp_ib.count = ib->count;
@@ -198,6 +212,11 @@ void vbo_rebase_prims( struct gl_context *ctx,
        */
       tmp_prims = malloc(sizeof(*prim) * nr_prims);
 
+      if (tmp_prims == NULL) {
+         _mesa_error_no_memory(__func__);
+         return;
+      }
+
       for (i = 0; i < nr_prims; i++) {
         /* If this fails, it could indicate an application error:
          */