diff options
author | Dmitri Pal <dpal@redhat.com> | 2009-07-10 11:43:05 -0400 |
---|---|---|
committer | Stephen Gallagher <sgallagh@redhat.com> | 2009-07-15 11:19:46 -0400 |
commit | 9689454cb2d3d3b3c9e02a32ab9db13f49e8d5a2 (patch) | |
tree | 8247496c0ca89532944b069467e67c875712e123 /common/collection/collection.c | |
parent | 1a91062d7d82407a6e376b62b29dca709170a66b (diff) | |
download | sssd-9689454cb2d3d3b3c9e02a32ab9db13f49e8d5a2.tar.gz sssd-9689454cb2d3d3b3c9e02a32ab9db13f49e8d5a2.tar.bz2 sssd-9689454cb2d3d3b3c9e02a32ab9db13f49e8d5a2.zip |
COLLECTION Fixed: iterator_up and insert_into_current
During a review of the previous patch the two issues
were found:
a) The col_iterator_up function was not implemented properly
so it got reworked. New implementation changes
the way error condition is handled. Comments were updated accordingly.
b) There was a mising check for validity of the argument in
the col_insert_into_current function. Check was added.
c) Unit test modified to reflect the change in functionality.
Diffstat (limited to 'common/collection/collection.c')
-rw-r--r-- | common/collection/collection.c | 18 |
1 files changed, 15 insertions, 3 deletions
diff --git a/common/collection/collection.c b/common/collection/collection.c index b4a2c8d5..1e3fe5c3 100644 --- a/common/collection/collection.c +++ b/common/collection/collection.c @@ -355,6 +355,10 @@ int col_insert_item_into_current(struct collection_item *collection, "Adding header item to new collection."); collection = item; } + else { + TRACE_ERROR_STRING("Passed in item is invalid", ""); + return EINVAL; + } } else { /* We can add items only to collections */ @@ -1243,6 +1247,9 @@ static int col_walk_items(struct collection_item *ci, TRACE_INFO_NUMBER("Mode flags:", mode_flags); /* Increase depth */ + /* NOTE: The depth is increased at the entry to the function. + * and decreased right before the exit so it is safe to decrease it. + */ (*depth)++; current = ci; @@ -2605,18 +2612,23 @@ int col_bind_iterator(struct collection_iterator **iterator, /* Stop processing this subcollection and move to the next item in the * collection 'level' levels up.*/ -int col_iterate_up(struct collection_iterator *iterator, int level) +int col_iterate_up(struct collection_iterator *iterator, unsigned level) { TRACE_FLOW_STRING("iterate_up", "Entry"); - if ((iterator == NULL) || (level >= iterator->stack_depth)) { + if (iterator == NULL) { TRACE_ERROR_NUMBER("Invalid parameter.", EINVAL); return EINVAL; } TRACE_INFO_NUMBER("Going up:", level); + TRACE_INFO_NUMBER("Current stack depth:", iterator->stack_depth); - iterator->stack_depth--; + /* If level is big just move to the top, + * that will end the iteration process. + */ + if (level >= iterator->stack_depth) iterator->stack_depth = 0; + else iterator->stack_depth -= level; TRACE_INFO_NUMBER("Stack depth at the end:", iterator->stack_depth); TRACE_FLOW_STRING("col_iterate_up", "Exit"); |