Browse Source

Added a null check

tree_alloc
Cameron Weinfurt 1 year ago
parent
commit
61c2a6f2f5
  1. 2
      Makefile
  2. 20
      tree_alloc.c

2
Makefile

@ -7,7 +7,7 @@ OUT_NAME = the_alloc
dev: CFLAGS= $(COMMON_FLAGS) -g -D UNIT_TESTS -D DEBUG=1
dev: $(OUT_NAME)
rm -f vgcore.*
valgrind ./$(OUT_NAME) 2&> debug_log.txt
valgrind ./$(OUT_NAME)
release: CFLAGS= $(COMMON_FLAGS) -O2
release: clean $(OUT_NAME)

20
tree_alloc.c

@ -138,12 +138,14 @@ void rotate_left(TreeAlloc **root_ptr, TreeAlloc *ta) {
tmp = ta->right;
parent = ta->parent;
ta->right = tmp->left;
if (ta->right) ta->right->parent = ta;
if (tmp) {
ta->right = tmp->left;
tmp->left = ta;
tmp->parent = parent;
}
tmp->left = ta;
if (ta->right) ta->right->parent = ta;
ta->parent = tmp;
tmp->parent = parent;
if (!parent) {
*root_ptr = tmp;
@ -160,12 +162,14 @@ void rotate_right(TreeAlloc **root_ptr, TreeAlloc *ta) {
tmp = ta->left;
parent = ta->parent;
ta->left = tmp->right;
if (ta->left) ta->left->parent = ta;
if (tmp) {
ta->left = tmp->right;
tmp->right = ta;
tmp->parent = parent;
}
tmp->right = ta;
if (ta->left) ta->left->parent = ta;
ta->parent = tmp;
tmp->parent = parent;
if (!parent) {
*root_ptr = tmp;

Loading…
Cancel
Save