Skip to content
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

Open
abdullahemad12 opened this issue Jan 21, 2019 · 0 comments
Open

Error handling in cbt_clone #26

abdullahemad12 opened this issue Jan 21, 2019 · 0 comments
Labels
enhancement New feature or request first-timers-only Good for new comers good first issue Good for newcomers help wanted Extra attention is needed Testing Testing a feature or a function

Comments

@abdullahemad12
Copy link
Owner

Task

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

Method

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.

Prototype

/**
  * 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

Tests

  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
@abdullahemad12 abdullahemad12 added enhancement New feature or request help wanted Extra attention is needed good first issue Good for newcomers Testing Testing a feature or a function first-timers-only Good for new comers labels Jan 21, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request first-timers-only Good for new comers good first issue Good for newcomers help wanted Extra attention is needed Testing Testing a feature or a function
Projects
None yet
Development

No branches or pull requests

1 participant