fix #27: identity_list_add now iterative
authorKrista Grothoff <krista@pep-project.org>
Sun, 17 Jul 2016 10:12:33 +0200
changeset 891e4c80fda31af
parent 890 06daf5bf9a1d
child 892 f1155b6285aa
fix #27: identity_list_add now iterative
src/identity_list.c
     1.1 --- a/src/identity_list.c	Sun Jul 17 10:00:48 2016 +0200
     1.2 +++ b/src/identity_list.c	Sun Jul 17 10:12:33 2016 +0200
     1.3 @@ -61,17 +61,26 @@
     1.4      if (id_list == NULL)
     1.5          return new_identity_list(ident);
     1.6  
     1.7 +    // empty list
     1.8      if (id_list->ident == NULL) {
     1.9 +        if (id_list->next)
    1.10 +            return NULL; // invalid list
    1.11 +            
    1.12          id_list->ident = ident;
    1.13 +        
    1.14 +        if (id_list->ident == NULL)
    1.15 +            return NULL;
    1.16 +        
    1.17          return id_list;
    1.18      }
    1.19 -    else if (id_list->next == NULL) {
    1.20 -        id_list->next = new_identity_list(ident);
    1.21 -        return id_list->next;
    1.22 -    }
    1.23 -    else {
    1.24 -        return identity_list_add(id_list->next, ident);
    1.25 -    }
    1.26 + 
    1.27 +    identity_list* list_curr = id_list;
    1.28 +    while (list_curr->next)
    1.29 +        list_curr = list_curr->next;
    1.30 +    
    1.31 +    list_curr->next = new_identity_list(ident);
    1.32 +    
    1.33 +    return list_curr->next;
    1.34  }
    1.35  
    1.36  DYNAMIC_API int identity_list_length(const identity_list *id_list)