Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add validation check of input parameters #8

Merged
merged 1 commit into from Jan 22, 2016
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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