diff options
-rw-r--r-- | src/llist.c | 8 |
1 files changed, 7 insertions, 1 deletions
diff --git a/src/llist.c b/src/llist.c index a85cfa9..e560408 100644 --- a/src/llist.c +++ b/src/llist.c @@ -99,7 +99,10 @@ llist_nth (llist_t *l, int n) { llist_item_t *i; - for (i = l->head; i && n > 0; n--) + if (n < 0) + return NULL; + + for (i = l->head; i && n != 0; n--) i = i->next; return i; @@ -267,6 +270,9 @@ llist_find_nth (llist_t *l, int n, long data, llist_fn_match_t fn_match) { llist_item_t *i; + if (n < 0) + return NULL; + for (i = l->head; i; i = i->next) { if (fn_match (i->data, data) && (n-- == 0)) |