diff options
author | nw1 <nw1@ae88bc3d-4319-0410-8dbf-d08b4c9d3795> | 1997-11-05 06:28:21 +0000 |
---|---|---|
committer | nw1 <nw1@ae88bc3d-4319-0410-8dbf-d08b4c9d3795> | 1997-11-05 06:28:21 +0000 |
commit | 4f46a27ae285f8253425963f4050ba6970fdb9af (patch) | |
tree | 76fb2d36409d8fc6013d6c6e0efe11f4ea52287f /ace | |
parent | c6bc888bdd568316c1cd38529999fbc31754a6e0 (diff) | |
download | ATCD-4f46a27ae285f8253425963f4050ba6970fdb9af.tar.gz |
Added more checks to ACE_Double_Linked_List::remove_element to prevent
double removal of elements.
Diffstat (limited to 'ace')
-rw-r--r-- | ace/Containers.cpp | 4 | ||||
-rw-r--r-- | ace/Containers.h | 6 |
2 files changed, 7 insertions, 3 deletions
diff --git a/ace/Containers.cpp b/ace/Containers.cpp index 0728099a65e..1a78ba29624 100644 --- a/ace/Containers.cpp +++ b/ace/Containers.cpp @@ -905,11 +905,13 @@ ACE_Double_Linked_List<T>::remove_element (T *item) // Notice that you have to ensure that item is an element of this // list. We can't do much checking here. - if (item == this->head_ || this->size () == 0) // Can't remove head + if (item == this->head_ || item->next_ == 0 + || item->prev_ == 0 || this->size () == 0) // Can't remove head return -1; item->prev_->next_ = item->next_; item->next_->prev_ = item->prev_; + item->next_ = item->prev_ = 0; // reset pointers to prevent double removal. this->size_--; return 0; } diff --git a/ace/Containers.h b/ace/Containers.h index 5a042a65488..af4b37d5c76 100644 --- a/ace/Containers.h +++ b/ace/Containers.h @@ -650,8 +650,10 @@ protected: int remove_element (T *item); // Remove an <item> from the list. Return 0 if succeed, -1 otherwise. - // Notice that this function only checks if item is <head_>. Users - // must ensure the item is in the list. + // Notice that this function checks if item is <head_> and either its + // <next_> or <prev_> is NULL. The function resets item's <next_> and + // <prev_> to 0 to prevent clobbering the double-linked list if a user + // tries to remove the same node again. T *head_; // Head of the circular double-linked list. |