4.9.3.6 Initialization by Copying [ToC] [Index]     [Skip Back] [Skip Fwd]     [Prev] [Up] [Next]

This function copies one traverser to another. It only copies the stack of parent pointers if they are up-to-date:

69. <BST traverser copy initializer 69> =
void *
bst_t_copy (struct bst_traverser *trav, const struct bst_traverser *src)
{ assert (trav != NULL && src != NULL); if (trav != src)
    { trav->bst_table = src->bst_table; trav->bst_node = src->bst_node; trav->bst_generation = src->bst_generation; if (trav->bst_generation == trav->bst_table->bst_generation)
        { trav->bst_height = src->bst_height; memcpy (trav->bst_stack, (const void *) src->bst_stack, sizeof *trav->bst_stack * trav->bst_height); } } return trav->bst_node != NULL ? trav->bst_node->bst_data : NULL; }

This code is included in 63 and 178.

Exercises:

1. Without the check that trav != src before copying src into trav, what might happen? [answer]