Skip to content

Commit c642e25

Browse files
authored
Merge pull request #36 from louen/patch-1
Fix pointer aliasing in kdtree
2 parents 36f571d + 6bffbb2 commit c642e25

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

Demos/Simulation/kdTree.inl

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11

22
#include "BoundingSphere.h"
3+
#include <cstring>
34
#include "omp.h"
45

56
template<typename HullType> void
@@ -127,8 +128,10 @@ KDTree<HullType>::traverse_breadth_first_parallel(TraversalPredicate pred,
127128
#endif
128129

129130
// compute ceiling of Log2
130-
Real d = maxThreads - 1;
131-
const unsigned int targetDepth = (*reinterpret_cast<long long*>(&d) >> 52) - 1022;
131+
// assuming double and long long have the same size.
132+
double d = maxThreads - 1;
133+
long long ll; memcpy( &ll, &d, sizeof(d));
134+
const unsigned int targetDepth = (ll >> 52) - 1022ll;
132135

133136
traverse_breadth_first(
134137
[&start_nodes, &maxThreads, &targetDepth](unsigned int node_index, unsigned int depth)
@@ -207,4 +210,4 @@ KDTree<HullType>::update()
207210
compute_hull_approx(nd.begin, nd.n, m_hulls[node_index]);
208211
}
209212
);
210-
}
213+
}

0 commit comments

Comments
 (0)