Revision: 56754
          http://sourceforge.net/p/brlcad/code/56754
Author:   brlcad
Date:     2013-08-12 19:19:38 +0000 (Mon, 12 Aug 2013)
Log Message:
-----------
do some more cleanup to make sure we don't dereference a null accidentally.  
almost a few more size_t vs intptr_t casts just they're different.

Modified Paths:
--------------
    brlcad/trunk/src/librt/primitives/bot/tie_kdtree.c

Modified: brlcad/trunk/src/librt/primitives/bot/tie_kdtree.c
===================================================================
--- brlcad/trunk/src/librt/primitives/bot/tie_kdtree.c  2013-08-12 18:54:59 UTC 
(rev 56753)
+++ brlcad/trunk/src/librt/primitives/bot/tie_kdtree.c  2013-08-12 19:19:38 UTC 
(rev 56754)
@@ -118,7 +118,7 @@
 {
     struct tie_kdtree_s *node_aligned = (struct tie_kdtree_s *)((intptr_t)node 
& ~0x7L);
 
-    if (TIE_HAS_CHILDREN(node_aligned->data)) {
+    if (node_aligned && node_aligned->data && 
TIE_HAS_CHILDREN(node_aligned->data)) {
        /* Node Data is KDTREE Children, Recurse */
        tie_kdtree_free_node(&((struct tie_kdtree_s 
*)(((intptr_t)(node_aligned->data)) & ~0x7L))[0]);
        tie_kdtree_free_node(&((struct tie_kdtree_s 
*)(((intptr_t)(node_aligned->data)) & ~0x7L))[1]);
@@ -126,13 +126,16 @@
        /* This node points to a geometry node, free it */
        struct tie_geom_s *tmp;
        tmp = (struct tie_geom_s *)((intptr_t)(node_aligned->data) & ~0x7L);
-       if (tmp->tri_num > 0) {
-           bu_free(tmp->tri_list, "tri_list");
+       if (tmp) {
+           if (tmp->tri_num > 0) {
+               bu_free(tmp->tri_list, "tri_list");
+           }
+           bu_free(tmp, "data");
        }
-       bu_free(tmp, "data");
     }
 }
 
+
 static void
 tie_kdtree_prep_head(struct tie_s *tie, struct tie_tri_s *tri_list, unsigned 
int tri_num)
 {
@@ -595,15 +598,15 @@
 
     /* Allocate 2 children nodes for the parent node */
     node->data = (void *)bu_calloc(2, sizeof(struct tie_kdtree_s), 
__FUNCTION__);
-    if(((size_t)node->data & 7L))
-       bu_log("node->data 0x%X is not aligned! %zu\n", node->data, 
(size_t)node->data & 7L);
+    if(((intptr_t)node->data & 0x7L))
+       bu_log("node->data 0x%X is not aligned! %zu\n", node->data, 
(intptr_t)node->data & 0x7L);
 
     BU_ALLOC(((struct tie_kdtree_s *)(node->data))[0].data, struct tie_geom_s);
-    if(((size_t)((struct tie_kdtree_s *)(node->data))[0].data & 7L))
+    if(((intptr_t)((struct tie_kdtree_s *)(node->data))[0].data & 0x7L))
        bu_log("node->data[0].data 0x%X is not aligned!\n", ((struct 
tie_kdtree_s *)(node->data))[0].data);
 
     BU_ALLOC(((struct tie_kdtree_s *)(node->data))[1].data, struct tie_geom_s);
-    if(((size_t)((struct tie_kdtree_s *)(node->data))[1].data & 7L))
+    if(((intptr_t)((struct tie_kdtree_s *)(node->data))[1].data & 0x7L))
        bu_log("node->data[1].data 0x%X is not aligned!\n", ((struct 
tie_kdtree_s *)(node->data))[1].data);
 
     /* Initialize Triangle List */
@@ -699,9 +702,10 @@
 {
     /* Free KDTREE Nodes */
     /* prevent tie from crashing when a tie_free() is called right after a 
tie_init() */
-    if (tie->kdtree)
+    if (tie->kdtree) {
        tie_kdtree_free_node(tie->kdtree);
-    bu_free(tie->kdtree, "kdtree");
+       bu_free(tie->kdtree, "kdtree");
+    }
 }
 
 void
@@ -729,8 +733,9 @@
     if (!already_built) {
        if (g->tri_num)
            g->tri_list = (struct tie_tri_s **)bu_realloc(g->tri_list, 
sizeof(struct tie_tri_s *) * g->tri_num, "prep tri_list");
-    } else
+    } else {
        bu_free(g->tri_list, "tri_list");
+    }
 
     /*
      * Compute Floating Fuzz Precision Value

This was sent by the SourceForge.net collaborative development platform, the 
world's largest Open Source development site.


------------------------------------------------------------------------------
Get 100% visibility into Java/.NET code with AppDynamics Lite!
It's a free troubleshooting tool designed for production.
Get down to code-level detail for bottlenecks, with <2% overhead. 
Download for free and get started troubleshooting in minutes. 
http://pubads.g.doubleclick.net/gampad/clk?id=48897031&iu=/4140/ostg.clktrk
_______________________________________________
BRL-CAD Source Commits mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/brlcad-commits

Reply via email to