fix #19: bloblist_add now iterative
authorKrista Grothoff <krista@pep-project.org>
Sun, 17 Jul 2016 20:21:57 +0200
changeset 899ce7ae6e03713
parent 898 2d2bd8d77f5e
child 900 2b8f651433ee
fix #19: bloblist_add now iterative
src/bloblist.c
     1.1 --- a/src/bloblist.c	Sun Jul 17 16:52:31 2016 +0200
     1.2 +++ b/src/bloblist.c	Sun Jul 17 20:21:57 2016 +0200
     1.3 @@ -95,11 +95,13 @@
     1.4          const char *mime_type, const char *filename)
     1.5  {
     1.6      assert(blob);
     1.7 -
     1.8 +    if (blob == NULL)
     1.9 +        return NULL;
    1.10 +    
    1.11      if (bloblist == NULL)
    1.12          return new_bloblist(blob, size, mime_type, filename);
    1.13  
    1.14 -    if (bloblist->value == NULL) {
    1.15 +    if (bloblist->value == NULL) { // empty list
    1.16          if (mime_type) {
    1.17              bloblist->mime_type = strdup(mime_type);
    1.18              if (bloblist->mime_type == NULL) {
    1.19 @@ -122,12 +124,19 @@
    1.20          return bloblist;
    1.21      }
    1.22  
    1.23 -    if (bloblist->next == NULL) {
    1.24 -        bloblist->next = new_bloblist(blob, size, mime_type, filename);
    1.25 -        return bloblist->next;
    1.26 -    }
    1.27 -
    1.28 -    return bloblist_add(bloblist->next, blob, size, mime_type, filename);
    1.29 +    bloblist_t* list_curr = bloblist;
    1.30 +    
    1.31 +    while (list_curr->next)
    1.32 +        list_curr = list_curr->next;
    1.33 +    
    1.34 +    list_curr->next = new_bloblist(blob, size, mime_type, filename);
    1.35 +    
    1.36 +    assert(list_curr->next);
    1.37 +    if (list_curr->next == NULL)
    1.38 +        return NULL;
    1.39 +   
    1.40 +    return list_curr->next;
    1.41 +    
    1.42  }
    1.43  
    1.44  DYNAMIC_API int bloblist_length(const bloblist_t *bloblist)