Merge pull request #2010 from hardening/list_return_value

Make LinkedList return errors when something fails
This commit is contained in:
Marc-André Moreau 2014-08-18 13:05:18 -04:00
commit 065d6f0c99
2 changed files with 14 additions and 8 deletions

View File

@ -247,10 +247,10 @@ WINPR_API void* LinkedList_Last(wLinkedList* list);
WINPR_API BOOL LinkedList_Contains(wLinkedList* list, void* value);
WINPR_API void LinkedList_Clear(wLinkedList* list);
WINPR_API void LinkedList_AddFirst(wLinkedList* list, void* value);
WINPR_API void LinkedList_AddLast(wLinkedList* list, void* value);
WINPR_API BOOL LinkedList_AddFirst(wLinkedList* list, void* value);
WINPR_API BOOL LinkedList_AddLast(wLinkedList* list, void* value);
WINPR_API void LinkedList_Remove(wLinkedList* list, void* value);
WINPR_API BOOL LinkedList_Remove(wLinkedList* list, void* value);
WINPR_API void LinkedList_RemoveFirst(wLinkedList* list);
WINPR_API void LinkedList_RemoveLast(wLinkedList* list);

View File

@ -124,11 +124,13 @@ void LinkedList_Clear(wLinkedList* list)
* Adds a new node containing the specified value at the start of the LinkedList.
*/
void LinkedList_AddFirst(wLinkedList* list, void* value)
BOOL LinkedList_AddFirst(wLinkedList* list, void* value)
{
wLinkedListNode* node;
node = (wLinkedListNode*) malloc(sizeof(wLinkedListNode));
if (!node)
return FALSE;
node->prev = node->next = NULL;
node->value = value;
@ -144,17 +146,20 @@ void LinkedList_AddFirst(wLinkedList* list, void* value)
}
list->count++;
return TRUE;
}
/**
* Adds a new node containing the specified value at the end of the LinkedList.
*/
void LinkedList_AddLast(wLinkedList* list, void* value)
BOOL LinkedList_AddLast(wLinkedList* list, void* value)
{
wLinkedListNode* node;
node = (wLinkedListNode*) malloc(sizeof(wLinkedListNode));
if (!node)
return FALSE;
node->prev = node->next = NULL;
node->value = value;
@ -170,13 +175,14 @@ void LinkedList_AddLast(wLinkedList* list, void* value)
}
list->count++;
return TRUE;
}
/**
* Removes the first occurrence of the specified value from the LinkedList.
*/
void LinkedList_Remove(wLinkedList* list, void* value)
BOOL LinkedList_Remove(wLinkedList* list, void* value)
{
wLinkedListNode* node;
@ -201,12 +207,12 @@ void LinkedList_Remove(wLinkedList* list, void* value)
free(node);
list->count--;
break;
return TRUE;
}
node = node->next;
}
return FALSE;
}
/**