merged, rebranched empty_attachments
authorEdouard Tisserant
Fri, 24 Jun 2016 11:41:32 +0200
branchempty_attachments
changeset 12521f6d0f5d86a
parent 124 ce9401d49537
parent 122 f4335bbf6d76
merged, rebranched
     1.1 --- a/pEp_utility.cpp	Fri Jun 24 03:43:42 2016 +0200
     1.2 +++ b/pEp_utility.cpp	Fri Jun 24 11:41:32 2016 +0200
     1.3 @@ -359,22 +359,33 @@
     1.4                  SafeArrayGetUBound(b.value, 1, &_ubound);
     1.5                  size_t size = _ubound - _lbound + 1;
     1.6  
     1.7 -                char *buffer = (char *) malloc(size);
     1.8 -                if (buffer == NULL)
     1.9 -                    throw bad_alloc();
    1.10 +                if (size > 1)
    1.11 +                {
    1.12 +                    char *buffer = (char *) malloc(size);
    1.13 +                    if (buffer == NULL)
    1.14 +                        throw bad_alloc();
    1.15  
    1.16 -                char *data;
    1.17 +                    char *data;
    1.18  
    1.19 -                SafeArrayAccessData(b.value, (void **) &data);
    1.20 -                memcpy(buffer, data, size);
    1.21 -                SafeArrayUnaccessData(sa);
    1.22 +                    SafeArrayAccessData(b.value, (void **) &data);
    1.23 +                    memcpy(buffer, data, size);
    1.24 +                    SafeArrayUnaccessData(sa);
    1.25  
    1.26 -                _bl = bloblist_add(_bl, buffer, size, str(b.mime_type), str(b.filename));
    1.27 -                if (_bl == NULL) {
    1.28 -                    free(buffer);
    1.29 -                    clear_blob(b);
    1.30 -                    free_bloblist(bl);
    1.31 -                    throw bad_alloc();
    1.32 +                    _bl = bloblist_add(_bl, buffer, size, str(b.mime_type), str(b.filename));
    1.33 +                    if (_bl == NULL) {
    1.34 +                        free(buffer);
    1.35 +                        clear_blob(b);
    1.36 +                        free_bloblist(bl);
    1.37 +                        throw bad_alloc();
    1.38 +                    }
    1.39 +                }
    1.40 +                else {
    1.41 +                    _bl = bloblist_add(_bl, NULL, 0, str(b.mime_type), str(b.filename));
    1.42 +                    if (_bl == NULL) {
    1.43 +                        clear_blob(b);
    1.44 +                        free_bloblist(bl);
    1.45 +                        throw bad_alloc();
    1.46 +                    }
    1.47                  }
    1.48  
    1.49                  clear_blob(b);