Permalink
Browse files

nw_prune no longer SEGVs, but result is wrong

  • Loading branch information...
1 parent 706030e commit 06fb2a444e3783a9e15f96735030dca6ff399374 @tjunier committed Apr 17, 2012
Showing with 13 additions and 2 deletions.
  1. +6 −0 src/link.c
  2. +2 −2 src/link.h
  3. +3 −0 src/prune.c
  4. +1 −0 tests/HRV_FMDV.nw
  5. +1 −0 tests/test_nw_prune_args
View
@@ -308,6 +308,12 @@ int swap_nodes(struct rnode *node)
int unlink_rnode(struct rnode *node)
{
+ if (is_root(node))
+ return UNLINK_RNODE_ROOT;
+
+ /* Don't unlink a node twice. This is both a waste of time and a risk
+ * of bugs, because the code assumes that a node to be unlinked is
+ * still linked. */
if (! node->linked) return UNLINK_RNODE_DONE;
struct rnode *parent = node->parent;
View
@@ -40,8 +40,8 @@ enum remove_child_status { RM_CHILD_HAS_NO_PARENT = -10, RM_CHILD_MEM_ERROR };
* nodes in the tree structure will still contain the spliced-out node (which
* is good anyway since you need it to free the spliced-out node).*/
-enum unlink_rnode_status { UNLINK_RNODE_DONE, UNLINK_RNODE_ROOT_CHILD,
- UNLINK_RNODE_ERROR };
+enum unlink_rnode_status { UNLINK_RNODE_DONE, UNLINK_RNODE_ROOT,
+ UNLINK_RNODE_ROOT_CHILD, UNLINK_RNODE_ERROR };
struct rnode;
View
@@ -198,6 +198,9 @@ void process_tree(struct rooted_tree *tree, set_t *cl_labels, bool reverse)
case UNLINK_RNODE_ERROR:
fprintf (stderr, "Memory error - exiting.\n");
exit(EXIT_FAILURE);
+ case UNLINK_RNODE_ROOT:
+ fprintf(stderr, "WARNING: root cannot be pruned.\n");
+ break;
default:
assert(0); /* programmer error */
}
View
@@ -0,0 +1 @@
+(FMDV-C,((((((((HRV16,HRV1B)52,(HRV24,HRV85)70)22,(HRV11,(HRV9,(HRV64,HRV94)32)54)1)17,(HRV39,HRV2)92)97,HRV89)62,(HRV78,HRV12)52)100,((((HRV37,HRV3)65,HRV14)89,(HRV52,HRV17)100)75,(HRV93,HRV27)99)83)48,((((POLIO3,((POLIO2,(POLIO1A,COXA18)22)38,COXA17)72)97,COXA1)76,(((ECHO1,COXB2)83,ECHO6)99,(HEV70,HEV68)99)70)64,(COXA14,(COXA6,COXA2))59)100)68);
@@ -4,3 +4,4 @@ def3: catarrhini.nw Macaca Simias
multi: catarrhini_mult.nw Homo Pan
rev: -v fagales.nw Fagaceae Myricaceae Juglandaceae Betulaceae
bug1: -v prune_segv.nw COXA18
+bug2: -v HRV_FMDV.nw HRV37 HRV3 HRV14 HRV52 HRV17 HRV93 HRV27 POLIO3 POLIO2 POLIO1A COXA18 COXA17 COXA1

0 comments on commit 06fb2a4

Please sign in to comment.