aboutsummaryrefslogtreecommitdiffstats
path: root/src/libstrongswan/utils/linked_list.c
diff options
context:
space:
mode:
authorMartin Willi <martin@strongswan.org>2006-11-02 14:25:58 +0000
committerMartin Willi <martin@strongswan.org>2006-11-02 14:25:58 +0000
commit3b449ce854e8d1a067142b9914294e785050b025 (patch)
tree2a0df0734bd8b775056bbd30a210e2180dc785d2 /src/libstrongswan/utils/linked_list.c
parent116b53b6bd2502c297a0e95f4f665d94062f78fa (diff)
downloadstrongswan-3b449ce854e8d1a067142b9914294e785050b025.tar.bz2
strongswan-3b449ce854e8d1a067142b9914294e785050b025.tar.xz
fixed very old bug in linked_list's remove_first and remove_last
Diffstat (limited to 'src/libstrongswan/utils/linked_list.c')
-rw-r--r--src/libstrongswan/utils/linked_list.c28
1 files changed, 18 insertions, 10 deletions
diff --git a/src/libstrongswan/utils/linked_list.c b/src/libstrongswan/utils/linked_list.c
index daf07e210..8c5068870 100644
--- a/src/libstrongswan/utils/linked_list.c
+++ b/src/libstrongswan/utils/linked_list.c
@@ -392,12 +392,12 @@ static void insert_first(private_linked_list_t *this, void *item)
*/
static status_t remove_first(private_linked_list_t *this, void **item)
{
- if (this->count == 0)
+ element_t *element = this->first;
+
+ if (element == NULL)
{
return NOT_FOUND;
}
-
- element_t *element = this->first;
if (element->next != NULL)
{
element->next->previous = NULL;
@@ -408,8 +408,13 @@ static status_t remove_first(private_linked_list_t *this, void **item)
{
*item = element->value;
}
- this->count--;
+ if (--this->count == 0)
+ {
+ this->last = NULL;
+ }
+
free(element);
+
return SUCCESS;
}
@@ -457,26 +462,29 @@ static void insert_last(private_linked_list_t *this, void *item)
*/
static status_t remove_last(private_linked_list_t *this, void **item)
{
- if (this->count == 0)
+ element_t *element = this->last;
+
+ if (element == NULL)
{
return NOT_FOUND;
}
-
- element_t *element = this->last;
-
if (element->previous != NULL)
{
element->previous->next = NULL;
}
this->last = element->previous;
-
+
if (item != NULL)
{
*item = element->value;
}
+ if (--this->count == 0)
+ {
+ this->first = NULL;
+ }
- this->count--;
free(element);
+
return SUCCESS;
}