From 17a2aadccd57b9cf65a4a2b239153c57e9192e27 Mon Sep 17 00:00:00 2001 From: root Date: Tue, 7 Apr 2020 01:29:58 -0700 Subject: [PATCH 1/1] Bug fixes --- actionlist.cc | 24 +++++++++++++++--------- actionlist.h | 4 +++- 2 files changed, 18 insertions(+), 10 deletions(-) diff --git a/actionlist.cc b/actionlist.cc index f859746c..9f335e90 100644 --- a/actionlist.cc +++ b/actionlist.cc @@ -5,8 +5,11 @@ #include actionlist::actionlist() : - _size(0) + head(NULL), + tail(NULL), + _size(0) { + root.parent = NULL; } actionlist::~actionlist() { @@ -44,9 +47,10 @@ sllnode * allnode::findPrev(modelclock_t index) { continue; } else { //found non-null... - if (totalshift != 0) - ptr = ptr->children[currindex]; + if (totalshift == 0) + return reinterpret_cast *>(((uintptr_t)ptr->children[currindex])& ACTMASK); //need to increment here... + ptr = ptr->children[currindex]; increment = increment >> ALLBITS; mask = mask >> ALLBITS; totalshift -= ALLBITS; @@ -59,7 +63,7 @@ sllnode * allnode::findPrev(modelclock_t index) { mask = mask << ALLBITS; totalshift += ALLBITS; - if (increment == 0) { + if (ptr == NULL) { return NULL; } } @@ -71,9 +75,10 @@ sllnode * allnode::findPrev(modelclock_t index) { if (ptr->children[currindex] != NULL) { if (totalshift != 0) { ptr = ptr->children[currindex]; + break; } else { allnode * act = ptr->children[currindex]; - sllnode * node = reinterpret_cast*>(((uintptr_t)act) & ALLMASK); + sllnode * node = reinterpret_cast*>(((uintptr_t)act) & ACTMASK); return node; } } @@ -100,7 +105,7 @@ void actionlist::addAction(ModelAction * act) { llnode->val = act; if (tmp == NULL) { ptr->children[index] = reinterpret_cast(((uintptr_t) llnode) | ISACT); - sllnode * llnodeprev = ptr->findPrev(index); + sllnode * llnodeprev = ptr->findPrev(clock); if (llnodeprev != NULL) { llnode->next = llnodeprev->next; @@ -131,10 +136,11 @@ void actionlist::addAction(ModelAction * act) { } else { //handle case where something else is here - sllnode * llnodeprev = reinterpret_cast*>(((uintptr_t) llnode) & ALLMASK); + sllnode * llnodeprev = reinterpret_cast*>(((uintptr_t) llnode) & ACTMASK); llnode->next = llnodeprev->next; llnode->prev = llnodeprev; - llnode->next->prev = llnode; + if (llnode->next != NULL) + llnode->next->prev = llnode; llnodeprev->next = llnode; ptr->children[index] = reinterpret_cast(((uintptr_t) llnode) | ISACT); } @@ -178,7 +184,7 @@ void actionlist::removeAction(ModelAction * act) { //not found return; } else { - sllnode * llnode = reinterpret_cast *>(((uintptr_t) tmp) & ALLMASK); + sllnode * llnode = reinterpret_cast *>(((uintptr_t) tmp) & ACTMASK); bool first = true; do { if (llnode->val == act) { diff --git a/actionlist.h b/actionlist.h index 70f90eb8..20f93fc9 100644 --- a/actionlist.h +++ b/actionlist.h @@ -4,7 +4,9 @@ #include "classlist.h" #include "stl-model.h" -#define ISACT 1 +#define ISACT ((uintptr_t) 1ULL) +#define ACTMASK (~ISACT) + #define ALLBITS 4 #define ALLNODESIZE (1 << ALLBITS) #define ALLMASK ((1 << ALLBITS)-1) -- 2.34.1