New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error handling in cbt_clone #26

abdullahemad12 opened this Issue Jan 21, 2019 · 0 comments


None yet
1 participant
Copy link

abdullahemad12 commented Jan 21, 2019


If the clone_object function is not NULL and the clone_object returns NULL for any reason it should terminate, free all the memory allocated so far for the clone and return NULL


When invoking the clone_object, check if the return value is NULL. If it is, then simply terminate and return NULL. You will have to check if the return value from the recursive call is NULL because of an error or because the leafs of the trees have been reached.


  * cranbtree_t*, void* (*)(void*) -> cranbtree_t*
  * EFFECTS: clones the given cranbtree_t and clones the user objects if the
  *                     the passed function pointer is not NULL
  * RETURNS: a pointer to the clone, or NULL if the given cbt is not valid or on failure
  * NOTE: if the function is NULL, clone will copy the original object pointers to the new 
  *                  clone . This you must be careful in this case when manipulating the objects and destroying
  *                  them. Otherwise, the tree will store copies of the objects
cranbtree_t *cbt_clone(cranbtree_t * cbt)

Where to code

You will need to modify the following functions

  • cbt_clone in src/cranbtree.c
  • cbt_copy_nodes in src/lib/clone.c


  1. write a new test that passes a helper that fails when being called to copy an object and make sure the return value of cbt_clone is NULL. Run valgrind to make sure there are no memory leaks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment