Skip to content

Commit

Permalink
Merge pull request #8 from hexingb/master
Browse files Browse the repository at this point in the history
Add validation check of input parameters
  • Loading branch information
fragglet committed Jan 22, 2016
2 parents f018c90 + 925fa22 commit 73948ad
Showing 1 changed file with 32 additions and 1 deletion.
33 changes: 32 additions & 1 deletion src/list.c
Expand Up @@ -60,6 +60,13 @@ ListEntry *list_prepend(ListEntry **list, ListValue data)
{
ListEntry *newentry;

if (list == NULL) {

/* not a valid list */

return NULL;
}

/* Create new entry */

newentry = malloc(sizeof(ListEntry));
Expand Down Expand Up @@ -87,6 +94,10 @@ ListEntry *list_append(ListEntry **list, ListValue data)
ListEntry *rover;
ListEntry *newentry;

if (list == NULL) {
return NULL;
}

/* Create new list entry */

newentry = malloc(sizeof(ListEntry));
Expand Down Expand Up @@ -124,16 +135,28 @@ ListEntry *list_append(ListEntry **list, ListValue data)

ListValue list_data(ListEntry *listentry)
{
if (listentry == NULL) {
return LIST_NULL;
}

return listentry->data;
}

ListEntry *list_prev(ListEntry *listentry)
{
if (listentry == NULL) {
return NULL;
}

return listentry->prev;
}

ListEntry *list_next(ListEntry *listentry)
{
if (listentry == NULL) {
return NULL;
}

return listentry->next;
}

Expand Down Expand Up @@ -234,7 +257,7 @@ int list_remove_entry(ListEntry **list, ListEntry *entry)
{
/* If the list is empty, or entry is NULL, always fail */

if (*list == NULL || entry == NULL) {
if (list == NULL || *list == NULL || entry == NULL) {
return 0;
}

Expand Down Expand Up @@ -285,6 +308,10 @@ unsigned int list_remove_data(ListEntry **list, ListEqualFunc callback,
ListEntry *rover;
ListEntry *next;

if (list == NULL || callback == NULL) {
return 0;
}

entries_removed = 0;

/* Iterate over the entries in the list */
Expand Down Expand Up @@ -343,6 +370,10 @@ static ListEntry *list_sort_internal(ListEntry **list,
ListEntry *less_list, *more_list;
ListEntry *less_list_end, *more_list_end;

if (list == NULL || compare_func == NULL) {
return NULL;
}

/* If there are less than two entries in this list, it is
* already sorted */

Expand Down

0 comments on commit 73948ad

Please sign in to comment.