Browse Source

added safeguards

Iver 1 month ago
parent
commit
c9e37268b1
4 changed files with 26 additions and 8 deletions
  1. BIN
      N-D_planning.jpeg
  2. BIN
      builds/liborangetree.so
  3. 1 7
      changelog.txt
  4. 25 1
      src/main/main.c

BIN
N-D_planning.jpeg


BIN
builds/liborangetree.so


+ 1 - 7
changelog.txt

@@ -1,7 +1 @@
--added example program
--added OT_iterate function
--tested everything (it works on my machine, let's push to prod!)
--added OT_erase
--OT_drop now doesn't free operand
--updated makefile
--fixed logic error in OT_free
+-added safeguard for if void operand

+ 25 - 1
src/main/main.c

@@ -41,6 +41,12 @@ void OT_erase(void* operand){
 }
 }
 
 
 void OT_append(void* operand, void* appendee){
 void OT_append(void* operand, void* appendee){
+    if (!operand){
+        operand = appendee;
+
+        return;
+    }
+
     struct OT_operand* app = (struct OT_operand*)appendee;
     struct OT_operand* app = (struct OT_operand*)appendee;
     
     
     struct OT_operand* last_element = (struct OT_operand*)OT_get_last(operand);
     struct OT_operand* last_element = (struct OT_operand*)OT_get_last(operand);
@@ -50,6 +56,12 @@ void OT_append(void* operand, void* appendee){
 }
 }
 
 
 void OT_prepend(void* operand, void* prependee){
 void OT_prepend(void* operand, void* prependee){
+    if (!operand){
+        operand = prependee;
+
+        return;
+    }
+
     struct OT_operand* pre = (struct OT_operand*)prependee;
     struct OT_operand* pre = (struct OT_operand*)prependee;
     
     
     struct OT_operand* first_element = (struct OT_operand*)OT_get_first(operand);
     struct OT_operand* first_element = (struct OT_operand*)OT_get_first(operand);
@@ -59,6 +71,12 @@ void OT_prepend(void* operand, void* prependee){
 }
 }
 
 
 void OT_insert_left(void* operand, void* insertee){
 void OT_insert_left(void* operand, void* insertee){
+    if (!operand){
+        operand = insertee;
+
+        return;
+    }
+
     struct OT_operand* oper = (struct OT_operand*)operand;
     struct OT_operand* oper = (struct OT_operand*)operand;
     struct OT_operand* ins = (struct OT_operand*)insertee;
     struct OT_operand* ins = (struct OT_operand*)insertee;
 
 
@@ -72,6 +90,12 @@ void OT_insert_left(void* operand, void* insertee){
 }
 }
 
 
 void OT_insert_right(void* operand, void* insertee){
 void OT_insert_right(void* operand, void* insertee){
+    if (!operand){
+        operand = insertee;
+
+        return;
+    }
+
     struct OT_operand* oper = (struct OT_operand*)operand;
     struct OT_operand* oper = (struct OT_operand*)operand;
     struct OT_operand* ins = (struct OT_operand*)insertee;
     struct OT_operand* ins = (struct OT_operand*)insertee;
 
 
@@ -99,7 +123,7 @@ void OT_free(void* operand){
 void OT_iterate(void* operand, void* user_pointer, void (*user_function)(void*, void*)){
 void OT_iterate(void* operand, void* user_pointer, void (*user_function)(void*, void*)){
     struct OT_operand* cur_oper = (struct OT_operand*)OT_get_first(operand);
     struct OT_operand* cur_oper = (struct OT_operand*)OT_get_first(operand);
 
 
-     while (cur_oper){
+    while (cur_oper){
         struct OT_operand* next = (struct OT_operand*)(cur_oper->OT_next);
         struct OT_operand* next = (struct OT_operand*)(cur_oper->OT_next);
         
         
         (*user_function)(cur_oper, user_pointer);
         (*user_function)(cur_oper, user_pointer);