From: erickson Date: Mon, 7 May 2007 14:26:56 +0000 (+0000) Subject: added some more index sanity checks. added const qualifier where necessary X-Git-Url: https://old-git.evergreen-ils.org/?a=commitdiff_plain;h=ad9021c5bca14563235889e026c6c1dab8bedad1;p=Evergreen.git added some more index sanity checks. added const qualifier where necessary git-svn-id: svn://svn.open-ils.org/ILS/trunk@7213 dcc99617-32d9-48b4-a31d-7c20da2025e4 --- diff --git a/OpenSRF/src/libstack/osrf_list.c b/OpenSRF/src/libstack/osrf_list.c index 0054c79d4d..0e58f0fa02 100644 --- a/OpenSRF/src/libstack/osrf_list.c +++ b/OpenSRF/src/libstack/osrf_list.c @@ -54,14 +54,13 @@ void* osrfListSet( osrfList* list, void* item, unsigned int position ) { void* olditem = osrfListRemove( list, position ); list->arrlist[position] = item; - //if( list->size == 0 || list->size <= position ) if( list->size <= position ) list->size = position + 1; return olditem; } -void* osrfListGetIndex( osrfList* list, unsigned int position ) { - if(!list || position >= list->size) return NULL; +void* osrfListGetIndex( const osrfList* list, unsigned int position ) { + if(!list || position >= list->size || position < 0) return NULL; return list->arrlist[position]; } @@ -80,8 +79,8 @@ void osrfListFree( osrfList* list ) { free(list); } -void* osrfListRemove( osrfList* list, int position ) { - if(!list || position >= list->size) return NULL; +void* osrfListRemove( osrfList* list, unsigned int position ) { + if(!list || position >= list->size || position < 0) return NULL; void* olditem = list->arrlist[position]; list->arrlist[position] = NULL; @@ -95,7 +94,7 @@ void* osrfListRemove( osrfList* list, int position ) { } -int osrfListFind( osrfList* list, void* addr ) { +int osrfListFind( const osrfList* list, void* addr ) { if(!(list && addr)) return -1; int index; for( index = 0; index < list->size; index++ ) { @@ -106,7 +105,7 @@ int osrfListFind( osrfList* list, void* addr ) { } -unsigned int osrfListGetCount( osrfList* list ) { +unsigned int osrfListGetCount( const osrfList* list ) { if(!list) return -1; return list->size; } @@ -118,9 +117,8 @@ void* osrfListPop( osrfList* list ) { } -osrfListIterator* osrfNewListIterator( osrfList* list ) { +osrfListIterator* osrfNewListIterator( const osrfList* list ) { if(!list) return NULL; - //osrfListIterator* itr = safe_malloc(sizeof(osrfListIterator)); osrfListIterator* itr; OSRF_MALLOC(itr, sizeof(osrfListIterator)); itr->list = list; diff --git a/OpenSRF/src/libstack/osrf_list.h b/OpenSRF/src/libstack/osrf_list.h index cc1a2b7af2..d829ab7115 100644 --- a/OpenSRF/src/libstack/osrf_list.h +++ b/OpenSRF/src/libstack/osrf_list.h @@ -26,7 +26,7 @@ typedef struct __osrfListStruct osrfList; struct __osrfListIteratorStruct { - osrfList* list; + const osrfList* list; unsigned int current; }; typedef struct __osrfListIteratorStruct osrfListIterator; @@ -37,7 +37,7 @@ osrfList* osrfNewListSize( unsigned int size ); /** Creates a new list iterator with the given list */ -osrfListIterator* osrfNewListIterator( osrfList* list ); +osrfListIterator* osrfNewListIterator( const osrfList* list ); /** Returns the next non-NULL item in the list, return NULL when @@ -99,7 +99,7 @@ void* osrfListSet( osrfList* list, void* item, unsigned int position ); @param list The list @param postiont the position */ -void* osrfListGetIndex( osrfList* list, unsigned int position ); +void* osrfListGetIndex( const osrfList* list, unsigned int position ); /** Frees the list and all list items (if the list has a "freeItem" function defined ) @@ -114,7 +114,7 @@ void osrfListFree( osrfList* list ); @return A pointer to the item removed if "freeItem" is not defined for this list, returns NULL if it is. */ -void* osrfListRemove( osrfList* list, int position ); +void* osrfListRemove( osrfList* list, unsigned int position ); /** Finds the list item whose void* is the same as the one passed in @@ -122,7 +122,7 @@ void* osrfListRemove( osrfList* list, int position ); @param addr The pointer connected to the list item we're to find @return the index of the item, or -1 if the item was not found */ -int osrfListFind( osrfList* list, void* addr ); +int osrfListFind( const osrfList* list, void* addr ); void __osrfListSetSize( osrfList* list ); @@ -131,7 +131,7 @@ void __osrfListSetSize( osrfList* list ); /** @return The number of non-null items in the list */ -unsigned int osrfListGetCount( osrfList* list ); +unsigned int osrfListGetCount( const osrfList* list ); /** * May be used as a default memory freeing call