2741837add7ced035f026298581e273dce6da507
angie
  Wed Sep 17 13:07:19 2014 -0700
Missing NULL check that somehow hid for a long time, then reared itsugly head when zoomed in to a small region in eboVir2.
I should really just switch vcfTrack over to using Jim's improved
hacTree, when the ebola dust settles.

diff --git src/lib/hacTree.c src/lib/hacTree.c
index f82aba6..c303cca 100644
--- src/lib/hacTree.c
+++ src/lib/hacTree.c
@@ -229,31 +229,37 @@
     {
     // Scan pool for node with lowest childDistance; swap that node w/head
     int bestIx = 0;
     double minScore = poolHead[0].childDistance;
     int i;
     for (i=1;  i < poolLength;  i++)
 	if (poolHead[i].childDistance < minScore)
 	    {
 	    minScore = poolHead[i].childDistance;
 	    bestIx = i;
 	    }
     if (bestIx != 0)
 	swapBytes((char *)&(poolHead[0]), (char *)&(poolHead[bestIx]), sizeof(struct hacTree));
     // Pop the best (lowest-distance) node from poolHead, make it root (for now).
     root = poolHead;
-    root->itemOrCluster = mergeF(root->left->itemOrCluster, root->right->itemOrCluster, extraData);
+    if (root->left && root->right)
+        root->itemOrCluster = mergeF(root->left->itemOrCluster, root->right->itemOrCluster,
+                                     extraData);
+    else if (root->left)
+        root->itemOrCluster = root->left->itemOrCluster;
+    else if (root->right)
+        root->itemOrCluster = root->right->itemOrCluster;
     poolHead = &(poolHead[1]);
     poolLength--;
     // Where root->left is found in the pool, replace it with root.
     // Where root->right is found, drop that node so it doesn't become
     // a duplicate of the replacement cases.
     int numNodesToDelete = 0;
     for (i=0;  i < poolLength;  i++)
 	{
 	struct hacTree *node = &(poolHead[i]);
 	if (node->left == root->left)
 	    // found root->left; replace node->left with root (merge root with node->right):
 	    initNode(node, root, node->right, distF, mergeF, extraData, FALSE);
 	else if (node->right == root->left)
 	    // found root->left; replace node->right with root (merge root with node->left):
 	    initNode(node, node->left, root, distF, mergeF, extraData, FALSE);