TP 9 exo2: Better handling of special cases in list_delete()
authorJerome Benoit <jerome.benoit@sap.com>
Fri, 3 Mar 2017 19:29:20 +0000 (20:29 +0100)
committerJerome Benoit <jerome.benoit@sap.com>
Fri, 3 Mar 2017 19:29:20 +0000 (20:29 +0100)
Signed-off-by: Jerome Benoit <jerome.benoit@sap.com>
TP_9/exo2/clist.c

index edc296473e54c3910d0d4ea5fe3c3058aaf2913a..9ebb34817e5982fa3b3131e388d01b320f6a3a70 100644 (file)
@@ -57,7 +57,9 @@ link_t* list_delete(link_t* head, unsigned index) {
     link_t* head_next = NULL;
     link_t* head_ret = NULL;
    
-    if (index == 0) {
+    if (head == NULL) {
+        return NULL;
+    } else if (index == 0) {
         head_next = head->next;
         free(head);
         head = head_next;