llvmpipe,draw,gallivm: Ensure we don't walk beyond the end of the shader variant...
authorJosé Fonseca <jfonseca@vmware.com>
Mon, 28 Nov 2011 16:54:09 +0000 (16:54 +0000)
committerJosé Fonseca <jfonseca@vmware.com>
Thu, 8 Dec 2011 17:59:33 +0000 (17:59 +0000)
u_simple_list.h uses a sentinel element, and not a NULL element. So
ensure list is not empty when reducing the list of shader variants.

Something I noticed while trying to free variants more aggressively.

Reviewed-by: Brian Paul <brianp@vmware.com>
src/gallium/auxiliary/draw/draw_pt_fetch_shade_pipeline_llvm.c
src/gallium/drivers/llvmpipe/lp_state_fs.c
src/gallium/drivers/llvmpipe/lp_state_setup.c

index 7698f5ff2af752e795cb95ebe9e40d96d4cffb70..de6ce7fad40cf5c28bb941c124c9e9adc9985536 100644 (file)
@@ -160,8 +160,13 @@ llvm_middle_end_prepare( struct draw_pt_middle_end *middle,
           * XXX: should we flush here ?
           */
          for (i = 0; i < DRAW_MAX_SHADER_VARIANTS / 4; i++) {
-            struct draw_llvm_variant_list_item *item =
-               last_elem(&fpme->llvm->vs_variants_list);
+            struct draw_llvm_variant_list_item *item;
+            if (is_empty_list(&fpme->llvm->vs_variants_list)) {
+               break;
+            }
+            item = last_elem(&fpme->llvm->vs_variants_list);
+            assert(item);
+            assert(item->base);
             draw_llvm_destroy_variant(item->base);
          }
       }
index 90f9271223c7f52892ba720f4cd73ca9f52d578e..26f8d7ff76578e14c084b0fba98dd9ebb8f08787 100644 (file)
@@ -1373,10 +1373,12 @@ llvmpipe_update_fs(struct llvmpipe_context *lp)
          if (lp->nr_fs_variants >= LP_MAX_SHADER_VARIANTS) {
             for (i = 0; i < LP_MAX_SHADER_VARIANTS / 4; i++) {
                struct lp_fs_variant_list_item *item;
-               item = last_elem(&lp->fs_variants_list);
-               if (!item) {
+               if (is_empty_list(&lp->fs_variants_list)) {
                   break;
                }
+               item = last_elem(&lp->fs_variants_list);
+               assert(item);
+               assert(item->base);
                llvmpipe_remove_shader_variant(lp, item->base);
             }
          }
index 97c9238f989e902830c3551d7f70b79abd2c7294..3243abff6e085c3ad3d15593bfb8d0a633a831d2 100644 (file)
@@ -837,7 +837,13 @@ cull_setup_variants(struct llvmpipe_context *lp)
    llvmpipe_finish(pipe, __FUNCTION__);
 
    for (i = 0; i < LP_MAX_SETUP_VARIANTS / 4; i++) {
-      struct lp_setup_variant_list_item *item = last_elem(&lp->setup_variants_list);
+      struct lp_setup_variant_list_item *item;
+      if (is_empty_list(&lp->setup_variants_list)) {
+         break;
+      }
+      item = last_elem(&lp->setup_variants_list);
+      assert(item);
+      assert(item->base);
       remove_setup_variant(lp, item->base);
    }
 }