Skip to content

Commit

Permalink
nw_prune no longer SEGVs, but result is wrong
Browse files Browse the repository at this point in the history
  • Loading branch information
Thomas Junier committed Apr 17, 2012
1 parent 706030e commit 06fb2a4
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 2 deletions.
6 changes: 6 additions & 0 deletions src/link.c
Expand Up @@ -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;
Expand Down
4 changes: 2 additions & 2 deletions src/link.h
Expand Up @@ -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;

Expand Down
3 changes: 3 additions & 0 deletions src/prune.c
Expand Up @@ -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 */
}
Expand Down
1 change: 1 addition & 0 deletions tests/HRV_FMDV.nw
@@ -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);
1 change: 1 addition & 0 deletions tests/test_nw_prune_args
Expand Up @@ -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.