fix #18: bloblist_dup now iterative.
authorKrista Grothoff <krista@pep-project.org>
Sun, 17 Jul 2016 20:59:35 +0200
changeset 902e9c70ca2bed6
parent 901 30725fee8f85
child 903 7a040beb4000
fix #18: bloblist_dup now iterative.
src/bloblist.c
     1.1 --- a/src/bloblist.c	Sun Jul 17 20:37:08 2016 +0200
     1.2 +++ b/src/bloblist.c	Sun Jul 17 20:59:35 2016 +0200
     1.3 @@ -64,7 +64,10 @@
     1.4      bloblist_t *bloblist = NULL;
     1.5  
     1.6      assert(src);
     1.7 +    if (src == NULL)
     1.8 +        return NULL;
     1.9  
    1.10 +    // head
    1.11      char *blob2 = malloc(src->size);
    1.12      assert(blob2);
    1.13      if (blob2 == NULL)
    1.14 @@ -77,12 +80,26 @@
    1.15          goto enomem;
    1.16      blob2 = NULL;
    1.17  
    1.18 -    if (src->next) {
    1.19 -        bloblist->next = bloblist_dup(src->next);
    1.20 -        if (bloblist->next == NULL)
    1.21 +    bloblist_t* src_curr = src->next;
    1.22 +    bloblist_t** dst_curr_ptr = &bloblist->next;
    1.23 +    
    1.24 +    // list
    1.25 +    while (src_curr) {
    1.26 +        blob2 = malloc(src_curr->size);
    1.27 +
    1.28 +        assert(blob2);
    1.29 +        if (blob2 == NULL)
    1.30              goto enomem;
    1.31 +
    1.32 +        memcpy(blob2, src_curr->value, src_curr->size);
    1.33 +        *dst_curr_ptr = new_bloblist(blob2, src_curr->size, src_curr->mime_type, src_curr->filename);
    1.34 +        if (*dst_curr_ptr == NULL)
    1.35 +            goto enomem;
    1.36 +        
    1.37 +        src_curr = src_curr->next;
    1.38 +        dst_curr_ptr = &((*dst_curr_ptr)->next);
    1.39      }
    1.40 -
    1.41 +        
    1.42      return bloblist;
    1.43  
    1.44  enomem: