summaryrefslogtreecommitdiffstats
path: root/common/collection/collection.c
diff options
context:
space:
mode:
authorDmitri Pal <dpal@redhat.com>2009-12-14 15:00:02 -0500
committerStephen Gallagher <sgallagh@redhat.com>2010-02-01 08:50:57 -0500
commit3c401be933498710042d9298870a9a5311f0c658 (patch)
tree68e26b68e3ed4c3cdba8b30f85a7f51161417813 /common/collection/collection.c
parent3994ec2219ab7c7d5afbea4dad189d6920f94bbc (diff)
downloadsssd-3c401be933498710042d9298870a9a5311f0c658.tar.gz
sssd-3c401be933498710042d9298870a9a5311f0c658.tar.xz
sssd-3c401be933498710042d9298870a9a5311f0c658.zip
COLLECTION: Fixing queue collection and unit tests.
This patch includes following functionality: 1) Fixed the invalid handling of the pointers in the collection when last element is removed from the collection. 2) Added unit test to verify the fix. 3) Modified the three unit test to be verbose on demand. 4) Switched the main of the unit test to use array of functions rather than big if statement.
Diffstat (limited to 'common/collection/collection.c')
-rw-r--r--common/collection/collection.c12
1 files changed, 7 insertions, 5 deletions
diff --git a/common/collection/collection.c b/common/collection/collection.c
index e3644e4e2..cde5db5d5 100644
--- a/common/collection/collection.c
+++ b/common/collection/collection.c
@@ -436,6 +436,7 @@ int col_insert_item_into_current(struct collection_item *collection,
if (col_find_property(collection, item->property, 0, 0, 0, &parent)) {
current = parent->next;
parent->next = current->next;
+ if (header->last == current) header->last = parent;
col_delete_item(current);
header->count--;
}
@@ -449,6 +450,7 @@ int col_insert_item_into_current(struct collection_item *collection,
TRACE_INFO_NUMBER("Current:", (unsigned)(parent->next));
current = parent->next;
parent->next = current->next;
+ if (header->last == current) header->last = parent;
col_delete_item(current);
header->count--;
}
@@ -463,7 +465,7 @@ int col_insert_item_into_current(struct collection_item *collection,
switch (disposition) {
case COL_DSP_END: /* Link new item to the last item in the list if there any */
- if (header->last != NULL) header->last->next = item;
+ if (header->count != 0) header->last->next = item;
/* Make sure we save a new last element */
header->last = item;
header->count++;
@@ -539,7 +541,7 @@ int col_insert_item_into_current(struct collection_item *collection,
}
else if(idx >= header->count - 1) {
/* In this case add to the end */
- if (header->last != NULL) header->last->next = item;
+ header->last->next = item;
/* Make sure we save a new last element */
header->last = item;
}
@@ -638,7 +640,7 @@ int col_extract_item_from_current(struct collection_item *collection,
*ret_ref = parent->next;
parent->next = NULL;
/* Special case - one data element */
- if (header->count == 2) header->last = NULL;
+ if (header->count == 2) header->last = collection;
else header->last = parent;
break;
@@ -646,7 +648,7 @@ int col_extract_item_from_current(struct collection_item *collection,
*ret_ref = collection->next;
collection->next = (*ret_ref)->next;
/* Special case - one data element */
- if (header->count == 2) header->last = NULL;
+ if (header->count == 2) header->last = collection;
break;
case COL_DSP_BEFORE: /* Check argument */
@@ -711,7 +713,7 @@ int col_extract_item_from_current(struct collection_item *collection,
*ret_ref = collection->next;
collection->next = (*ret_ref)->next;
/* Special case - one data element */
- if (header->count == 2) header->last = NULL;
+ if (header->count == 2) header->last = collection;
}
/* Index 0 stands for the first data element.
* Count includes header element.