Create zrealloc and change zmalloc so they assert that memory is allocated.
authorJonathan Dieter <jdieter@gmail.com>
Fri, 14 Sep 2018 13:51:17 +0000 (14:51 +0100)
committerJonathan Dieter <jdieter@gmail.com>
Fri, 14 Sep 2018 13:51:17 +0000 (14:51 +0100)
Remove NULL checks after zmalloc and zrealloc.

Signed-off-by: Jonathan Dieter <jdieter@gmail.com>
13 files changed:
src/lib/comp/comp.c
src/lib/comp/nocomp/nocomp.c
src/lib/comp/zstd/zstd.c
src/lib/dl/dl.c
src/lib/dl/multipart.c
src/lib/dl/range.c
src/lib/hash/hash.c
src/lib/header.c
src/lib/index/index_create.c
src/lib/index/index_read.c
src/lib/io.c
src/lib/zck.c
src/lib/zck_private.h

index 5f540462af4b9f9ea766c77e29e93f45aa1a0698..c3bd09a65955ccdc44d858ff1076fa188242965d 100644 (file)
@@ -115,12 +115,7 @@ static bool comp_add_to_data(zckCtx *zck, zckComp *comp, const char *src,
     ALLOCD_BOOL(zck, comp);
     ALLOCD_BOOL(zck, src);
 
-    comp->data = realloc(comp->data, comp->data_size + src_size);
-    if(comp->data == NULL) {
-        set_fatal_error(zck, "Unable to reallocate %lu bytes",
-                        comp->data_size + src_size);
-        return false;
-    }
+    comp->data = zrealloc(comp->data, comp->data_size + src_size);
     zck_log(ZCK_LOG_DEBUG, "Adding %lu bytes to compressed buffer",
         src_size);
     memcpy(comp->data + comp->data_size, src, src_size);
@@ -390,11 +385,6 @@ bool comp_add_to_dc(zckCtx *zck, zckComp *comp, const char *src,
 
     /* Get rid of any already read data and allocate space for new data */
     char *temp = zmalloc(comp->dc_data_size - comp->dc_data_loc + src_size);
-    if(temp == NULL) {
-        set_fatal_error(zck, "Unable to allocate %lu bytes",
-                        comp->dc_data_size - comp->dc_data_loc + src_size);
-        return false;
-    }
     if(comp->dc_data_loc != 0)
         zck_log(ZCK_LOG_DEBUG, "Freeing %lu bytes from decompressed buffer",
                 comp->dc_data_loc);
@@ -431,10 +421,6 @@ ssize_t comp_read(zckCtx *zck, char *dst, size_t dst_size, bool use_dict) {
 
     size_t dc = 0;
     char *src = zmalloc(dst_size - dc);
-    if(src == NULL) {
-        set_fatal_error(zck, "Unable to allocate %lu bytes", dst_size-dc);
-        return false;
-    }
     bool finished_rd = false;
     bool finished_dc = false;
     zck_log(ZCK_LOG_DEBUG, "Trying to read %lu bytes", dst_size);
index 90b480d22d221f411dcfae86c4cc2e6dbeb679e9..60ed9e7ebcf1da7c4a5493cc35f11d8c9b5267d7 100644 (file)
@@ -24,7 +24,6 @@
  * POSSIBILITY OF SUCH DAMAGE.
  */
 
-#include <assert.h>
 #include <stdlib.h>
 #include <stdint.h>
 #include <stdbool.h>
@@ -50,7 +49,6 @@ static ssize_t compress(zckCtx *zck, zckComp *comp, const char *src,
     ALLOCD_INT(zck, comp);
 
     *dst = zmalloc(src_size);
-    assert(*dst);
 
     memcpy(*dst, src, src_size);
     *dst_size = src_size;
index 939740e9a7822898ea8888e900133e093f668212..1e98b4f287770f6860d520607de4f88c7f721ddf 100644 (file)
@@ -24,7 +24,6 @@
  * POSSIBILITY OF SUCH DAMAGE.
  */
 
-#include <assert.h>
 #include <stdlib.h>
 #include <stdint.h>
 #include <stdbool.h>
@@ -93,8 +92,7 @@ static ssize_t compress(zckCtx *zck, zckComp *comp, const char *src,
     ALLOCD_INT(zck, dst_size);
     ALLOCD_INT(zck, comp);
 
-    comp->dc_data = realloc(comp->dc_data, comp->dc_data_size + src_size);
-    assert(comp->dc_data);
+    comp->dc_data = zrealloc(comp->dc_data, comp->dc_data_size + src_size);
 
     memcpy(comp->dc_data + comp->dc_data_size, src, src_size);
     *dst = NULL;
@@ -117,7 +115,6 @@ static bool end_cchunk(zckCtx *zck, zckComp *comp, char **dst, size_t *dst_size,
     }
 
     *dst = zmalloc(max_size);
-    assert(*dst);
 
     /* Currently, compression isn't deterministic when using contexts in
      * zstd 1.3.5, so this works around it */
@@ -163,9 +160,7 @@ static bool end_dchunk(zckCtx *zck, zckComp *comp, const bool use_dict,
     comp->data_size = 0;
 
     char *dst = zmalloc(fd_size);
-    assert(dst);
-
-    size_t retval;
+    size_t retval = 0;
     zck_log(ZCK_LOG_DEBUG, "Decompressing %lu bytes to %lu bytes", src_size,
             fd_size);
     if(use_dict && comp->ddict_ctx) {
index 44d3c5afa8ff028f6c20d75bb616aa33f5824355..bec3c98f128564508cd22b82faf2aca911a46df5 100644 (file)
@@ -283,18 +283,10 @@ ssize_t PUBLIC zck_dl_get_bytes_uploaded(zckDL *dl) {
 
 /* Initialize zckDL.  When finished, zckDL *must* be freed by zck_dl_free() */
 zckDL PUBLIC *zck_dl_init(zckCtx *zck) {
+    VALIDATE_PTR(zck);
+
     zckDL *dl = zmalloc(sizeof(zckDL));
-    if(!dl) {
-        set_fatal_error(zck, "Unable to allocate %lu bytes for zckDL",
-                        sizeof(zckDL));
-        return NULL;
-    }
     dl->mp = zmalloc(sizeof(zckMP));
-    if(!dl->mp) {
-        set_fatal_error(zck, "Unable to allocate %lu bytes for dl->mp",
-                        sizeof(zckMP));
-        return NULL;
-    }
     dl->zck = zck;
     return dl;
 }
@@ -303,6 +295,7 @@ zckDL PUBLIC *zck_dl_init(zckCtx *zck) {
 void PUBLIC zck_dl_reset(zckDL *dl) {
     if(!dl)
         return;
+
     reset_mp(dl->mp);
     dl->dl_chunk_data = 0;
     clear_dl_regex(dl);
index 78ebc7096c91bcac191d902dc0574d019ef07625..d6cdd0484e6ed770a9c7b33168fc79e6a57e61df 100644 (file)
@@ -24,7 +24,6 @@
  * POSSIBILITY OF SUCH DAMAGE.
  */
 
-#include <assert.h>
 #include <stdlib.h>
 #include <stdint.h>
 #include <stdbool.h>
@@ -42,7 +41,6 @@ static char *add_boundary_to_regex(zckCtx *zck, const char *regex,
     if(regex == NULL || boundary == NULL)
         return NULL;
     char *regex_b = zmalloc(strlen(regex) + strlen(boundary) + 1);
-    assert(regex_b);
     if(snprintf(regex_b, strlen(regex) + strlen(boundary), regex,
                 boundary) != strlen(regex) + strlen(boundary) - 2) {
         free(regex_b);
@@ -117,12 +115,7 @@ size_t multipart_extract(zckDL *dl, char *b, size_t l) {
 
     /* Add new data to stored buffer */
     if(mp->buffer) {
-        buf = realloc(mp->buffer, mp->buffer_len + l);
-        if(buf == NULL) {
-            set_fatal_error(dl->zck, "Unable to reallocate %lu bytes for zckDL",
-                            mp->buffer_len + l);
-            return 0;
-        }
+        buf = zrealloc(mp->buffer, mp->buffer_len + l);
         memcpy(buf + mp->buffer_len, b, l);
         l = mp->buffer_len + l;
         mp->buffer = NULL;  // No need to free, buf holds realloc'd buffer
@@ -163,7 +156,7 @@ size_t multipart_extract(zckDL *dl, char *b, size_t l) {
         if(i >= end) {
             size_t size = buf + l - header_start;
             if(size > 0) {
-                mp->buffer = malloc(size);
+                mp->buffer = zmalloc(size);
                 memcpy(mp->buffer, header_start, size);
                 mp->buffer_len = size;
             }
@@ -232,11 +225,6 @@ size_t multipart_get_boundary(zckDL *dl, char *b, size_t size) {
     /* Copy buffer to null-terminated string because POSIX regex requires null-
      * terminated string */
     char *buf = zmalloc(size+1);
-    if(buf == NULL) {
-        set_fatal_error(dl->zck, "Unable to allocate %lu bytes for header",
-                        size+1);
-        return 0;
-    }
     buf[size] = '\0';
     memcpy(buf, b, size);
 
index eb25b16bb7438f83a0cb4e6e6288a02c5d40b436..5875620b6d055154926ba7cc4ec57e6da10e49af 100644 (file)
@@ -42,11 +42,6 @@ static zckRangeItem *range_insert_new(zckCtx *zck, zckRangeItem *prev,
     VALIDATE_PTR(zck);
 
     zckRangeItem *new = zmalloc(sizeof(zckRangeItem));
-    if(!new) {
-        set_fatal_error(zck, "Unable to allocate %lu bytes",
-                        sizeof(zckRangeItem));
-        return NULL;
-    }
     new->start = start;
     new->end = end;
     if(prev) {
@@ -154,13 +149,8 @@ void PUBLIC zck_range_free(zckRange **info) {
 }
 
 char PUBLIC *zck_get_range_char(zckCtx *zck, zckRange *range) {
-    int buf_size=BUF_SIZE;
-    char *output=malloc(buf_size);
-    if(!output) {
-        set_fatal_error(zck, "Unable to allocate %lu bytes", buf_size);
-        return NULL;
-    }
-
+    int buf_size = BUF_SIZE;
+    char *output = zmalloc(buf_size);
     int loc = 0;
     int count = 0;
     zckRangeItem *ri = range->first;
@@ -175,11 +165,7 @@ char PUBLIC *zck_get_range_char(zckCtx *zck, zckRange *range) {
         }
         if(length > buf_size-loc) {
             buf_size = (int)(buf_size * 1.5);
-            output = realloc(output, buf_size);
-            if(output == NULL) {
-                set_fatal_error(zck, "Unable to allocate %lu bytes", buf_size);
-                return NULL;
-            }
+            output = zrealloc(output, buf_size);
             continue;
         }
         loc += length;
@@ -187,12 +173,7 @@ char PUBLIC *zck_get_range_char(zckCtx *zck, zckRange *range) {
         ri = ri->next;
     }
     output[loc-1]='\0'; // Remove final comma
-    output = realloc(output, loc);
-    if(output == NULL) {
-        set_fatal_error(zck, "Unable to shrink range to %lu bytes", loc);
-        free(output);
-        return NULL;
-    }
+    output = zrealloc(output, loc);
     return output;
 }
 
@@ -200,10 +181,6 @@ zckRange PUBLIC *zck_get_missing_range(zckCtx *zck, int max_ranges) {
     VALIDATE_PTR(zck);
 
     zckRange *range = zmalloc(sizeof(zckRange));
-    if(range == NULL) {
-        set_fatal_error(zck, "Unable to allocate %lu bytes", sizeof(zckRange));
-        return NULL;
-    }
     for(zckChunk *chk = zck->index.first; chk; chk = chk->next) {
         if(chk->valid)
             continue;
index 9ce8c86eac301b413f9c71fd2177e79bffb37bdb..69d543443122c53ea77e938015dba5dad2b20cc9 100644 (file)
@@ -214,16 +214,12 @@ bool hash_init(zckCtx *zck, zckHash *hash, zckHashType *hash_type) {
         zck_log(ZCK_LOG_DDEBUG, "Initializing SHA-1 hash");
         hash->ctx = zmalloc(sizeof(SHA_CTX));
         hash->type = hash_type;
-        if(hash->ctx == NULL)
-            return false;
         SHA1_Init((SHA_CTX *) hash->ctx);
         return true;
     } else if(hash_type->type == ZCK_HASH_SHA256) {
         zck_log(ZCK_LOG_DDEBUG, "Initializing SHA-256 hash");
         hash->ctx = zmalloc(sizeof(SHA256_CTX));
         hash->type = hash_type;
-        if(hash->ctx == NULL)
-            return false;
         SHA256_Init((SHA256_CTX *) hash->ctx);
         return true;
     } else if(hash_type->type >= ZCK_HASH_SHA512 &&
@@ -231,8 +227,6 @@ bool hash_init(zckCtx *zck, zckHash *hash, zckHashType *hash_type) {
         zck_log(ZCK_LOG_DDEBUG, "Initializing SHA-512 hash");
         hash->ctx = zmalloc(sizeof(SHA512_CTX));
         hash->type = hash_type;
-        if(hash->ctx == NULL)
-            return false;
         SHA512_Init((SHA512_CTX *) hash->ctx);
         return true;
     }
index 20be61a6930b3cffaf03b52eff511ebdf1aae065..4cf8be8791c943e9fca6f2191b127fd8694e6ec1 100644 (file)
@@ -50,12 +50,7 @@ static bool check_flags(zckCtx *zck, size_t flags) {
 
 static bool read_header_from_file(zckCtx *zck) {
     /* Allocate header and store any extra bytes at beginning of header */
-    zck->header = realloc(zck->header, zck->lead_size + zck->header_length);
-    if(zck->header == NULL) {
-        set_fatal_error(zck, "Unable to reallocate %lu bytes",
-                        zck->lead_size + zck->header_length);
-        return false;
-    }
+    zck->header = zrealloc(zck->header, zck->lead_size + zck->header_length);
     zck->lead_string = zck->header;
     char *header = zck->header + zck->lead_size;
     size_t loaded = 0;
@@ -111,11 +106,6 @@ static bool read_preface(zckCtx *zck) {
         return false;
     }
     zck->full_hash_digest = zmalloc(zck->hash_type.digest_size);
-    if(!zck->full_hash_digest) {
-        set_fatal_error(zck, "Unable to allocate %lu bytes",
-                        zck->hash_type.digest_size);
-        return false;
-    }
     memcpy(zck->full_hash_digest, header+length, zck->hash_type.digest_size);
     length += zck->hash_type.digest_size;
 
@@ -214,10 +204,6 @@ static bool preface_create(zckCtx *zck) {
     int header_malloc = zck->hash_type.digest_size + 4 + 2*MAX_COMP_SIZE;
 
     char *header = zmalloc(header_malloc);
-    if(header == NULL) {
-        set_error(zck, "Unable to allocate %lu bytes", header_malloc);
-        return false;
-    }
     size_t length = 0;
 
     /* Write out the full data digest */
@@ -238,11 +224,7 @@ static bool preface_create(zckCtx *zck) {
     compint_from_size(header+length, zck->index_size, &length);
 
     /* Shrink header to actual size */
-    header = realloc(header, length);
-    if(header == NULL) {
-        set_fatal_error(zck, "Unable to reallocate %lu bytes", length);
-        return false;
-    }
+    header = zrealloc(header, length);
 
     zck->preface_string = header;
     zck->preface_size = length;
@@ -252,10 +234,6 @@ static bool preface_create(zckCtx *zck) {
 
 static bool sig_create(zckCtx *zck) {
     char *header = zmalloc(MAX_COMP_SIZE);
-    if(header == NULL) {
-        set_error(zck, "Unable to allocate %lu bytes", MAX_COMP_SIZE);
-        return false;
-    }
     size_t length = 0;
 
     zck_log(ZCK_LOG_DEBUG, "Calculating %i signatures", zck->sigs.count);
@@ -277,10 +255,6 @@ static bool sig_create(zckCtx *zck) {
 static bool lead_create(zckCtx *zck) {
     int phs = 5 + 2*MAX_COMP_SIZE + zck->hash_type.digest_size;
     char *header = zmalloc(phs);
-    if(header == NULL) {
-        set_error(zck, "Unable to allocate %lu bytes", phs);
-        return false;
-    }
     size_t length = 0;
     memcpy(header, "\0ZCK1", 5);
     length += 5;
@@ -294,11 +268,7 @@ static bool lead_create(zckCtx *zck) {
     zck->hdr_digest_loc = length;
     length += zck->hash_type.digest_size;
 
-    header = realloc(header, length);
-    if(header == NULL) {
-        set_fatal_error(zck, "Unable to reallocate %lu bytes", length);
-        return false;
-    }
+    header = zrealloc(header, length);
 
     zck->lead_string = header;
     zck->lead_size = length;
@@ -339,11 +309,6 @@ bool header_create(zckCtx *zck) {
     zck_log(ZCK_LOG_DEBUG, "Merging into header: %lu bytes",
             zck->data_offset);
     zck->header = zmalloc(zck->data_offset);
-    if(zck->header == NULL) {
-        set_fatal_error(zck, "Unable to allocate %lu bytes",
-                        zck->data_offset);
-        return false;
-    }
     size_t offs = 0;
     memcpy(zck->header + offs, zck->lead_string, zck->lead_size);
     free(zck->lead_string);
@@ -403,10 +368,6 @@ static bool read_lead(zckCtx *zck) {
     int lead = 5 + 2*MAX_COMP_SIZE;
 
     char *header = zmalloc(lead);
-    if(header == NULL) {
-        set_error(zck, "Unable to allocate %lu bytes", lead);
-        return false;
-    }
     size_t length = 0;
 
     if(read_data(zck, header, lead) < lead) {
@@ -455,15 +416,7 @@ static bool read_lead(zckCtx *zck) {
 
     /* Read header digest */
     zck_log(ZCK_LOG_DEBUG, "Reading header digest");
-    header = realloc(header, length + zck->hash_type.digest_size);
-    if(header == NULL) {
-        zck->header_length = 0;
-        zck->hdr_digest_loc = 0;
-        hash_reset(&(zck->hash_type));
-        set_fatal_error(zck, "Unable to re-allocate %lu bytes",
-                        length + zck->hash_type.digest_size);
-        return false;
-    }
+    header = zrealloc(header, length + zck->hash_type.digest_size);
     size_t to_read = 0;
     if(lead < length + zck->hash_type.digest_size)
         to_read = length + zck->hash_type.digest_size - lead;
@@ -492,15 +445,6 @@ static bool read_lead(zckCtx *zck) {
         return false;
     }
     zck->header_digest = zmalloc(zck->hash_type.digest_size);
-    if(zck->header_digest == NULL) {
-        free(header);
-        zck->header_length = 0;
-        zck->hdr_digest_loc = 0;
-        hash_reset(&(zck->hash_type));
-        set_error(zck, "Unable to allocate %lu bytes",
-                  zck->hash_type.digest_size);
-        return false;
-    }
     memcpy(zck->header_digest, header + length, zck->hash_type.digest_size);
     length += zck->hash_type.digest_size;
 
index ec09192161506267d3945a632b6700c4ed632c4d..dd6b56491c85c59b5a74d5b2f90fad9eee1b75f8 100644 (file)
@@ -37,11 +37,6 @@ static bool create_chunk(zckCtx *zck) {
 
     clear_work_index(zck);
     zck->work_index_item = zmalloc(sizeof(zckChunk));
-    if(zck->work_index_item == NULL) {
-        set_error(zck, "Unable to allocate %lu bytes",
-                  sizeof(zckChunk));
-        return false;
-    }
     if(!hash_init(zck, &(zck->work_index_hash), &(zck->chunk_hash_type)))
         return false;
     return true;
@@ -54,10 +49,6 @@ static bool finish_chunk(zckIndex *index, zckChunk *item, char *digest,
     ALLOCD_BOOL(zck, item);
 
     item->digest = zmalloc(index->digest_size);
-    if(item->digest == NULL) {
-        set_error(zck, "Unable to allocate %lu bytes", index->digest_size);
-        return false;
-    }
     if(digest) {
         memcpy(item->digest, digest, index->digest_size);
         item->digest_size = index->digest_size;
@@ -123,11 +114,7 @@ bool index_create(zckCtx *zck) {
         }
     }
     /* Shrink index to actual size */
-    index = realloc(index, index_size);
-    if(index == NULL) {
-        set_fatal_error(zck, "Unable to reallocate %lu bytes", index_size);
-        return false;
-    }
+    index = zrealloc(index, index_size);
     zck->index_string = index;
     zck->index_size = index_size;
     zck_log(ZCK_LOG_DEBUG, "Generated index: %lu bytes", zck->index_size);
@@ -147,10 +134,6 @@ bool index_new_chunk(zckCtx *zck, zckIndex *index, char *digest, int digest_size
         return false;
     }
     zckChunk *chk = zmalloc(sizeof(zckChunk));
-    if(chk == NULL) {
-        set_error(zck, "Unable to allocate %lu bytes", sizeof(zckChunk));
-        return false;
-    }
     index->digest_size = digest_size;
     chk->comp_length = comp_size;
     chk->length = orig_size;
@@ -195,11 +178,6 @@ bool index_finish_chunk(zckCtx *zck) {
         }
     } else {
         digest = zmalloc(zck->chunk_hash_type.digest_size);
-        if(digest == NULL) {
-            set_fatal_error(zck, "Unable to allocate %lu bytes",
-                            zck->chunk_hash_type.digest_size);
-            return false;
-        }
     }
     if(!finish_chunk(&(zck->index), zck->work_index_item, digest, true, zck))
         return false;
index f30804096ca850db9581a95774b8925c671dfa07..a8b72726a48b94be98ca50f28ec3267ed6a2266b 100644 (file)
@@ -24,7 +24,6 @@
  * POSSIBILITY OF SUCH DAMAGE.
  */
 
-#include <assert.h>
 #include <stdlib.h>
 #include <stdint.h>
 #include <stdbool.h>
@@ -68,12 +67,9 @@ bool index_read(zckCtx *zck, char *data, size_t size, size_t max_length) {
         }
 
         zckChunk *new = zmalloc(sizeof(zckChunk));
-        assert(new);
 
         /* Read index entry digest */
         new->digest = zmalloc(zck->index.digest_size);
-        assert(new->digest);
-
         memcpy(new->digest, data+length, zck->index.digest_size);
         new->digest_size = zck->index.digest_size;
         length += zck->index.digest_size;
index 1b3e3b6dbb902d0d9d27c9586c5c455b6870566e..1e22e87f5419ed83265f08642939f9d09ec8eeda 100644 (file)
@@ -101,8 +101,6 @@ ssize_t tell_data(zckCtx *zck) {
 int chunks_from_temp(zckCtx *zck) {
     int read_count;
     char *data = zmalloc(BUF_SIZE);
-    if(data == NULL)
-        return false;
 
     if(lseek(zck->temp_fd, 0, SEEK_SET) == -1)
         return false;
index eb58f8aee81b6bb1a9fb673fc755593ab4309280..fd0406794da8a51a5793090d0824a2597ebb19c0 100644 (file)
@@ -24,6 +24,7 @@
  * POSSIBILITY OF SUCH DAMAGE.
  */
 
+#include <assert.h>
 #include <stdlib.h>
 #include <stdio.h>
 #include <stdint.h>
@@ -93,10 +94,6 @@ static int hex_to_int (char c) {
 static char *ascii_checksum_to_bin (zckCtx *zck, char *checksum) {
     int cl = strlen(checksum);
     char *raw_checksum = zmalloc(cl/2);
-    if(raw_checksum == NULL) {
-        set_error(zck, "Unable to allocate %lu bytes", cl/2);
-        return NULL;
-    }
     char *rp = raw_checksum;
     int buf = 0;
     for (int i=0; i<cl; i++) {
@@ -110,6 +107,18 @@ static char *ascii_checksum_to_bin (zckCtx *zck, char *checksum) {
     return raw_checksum;
 }
 
+void *zmalloc(size_t size) {
+    void *ret = calloc(1, size);
+    assert(ret);
+    return ret;
+}
+
+void *zrealloc(void *ptr, size_t size) {
+    void *ret = realloc(ptr, size);
+    assert(ret);
+    return ret;
+}
+
 int get_tmp_fd(zckCtx *zck) {
     VALIDATE_BOOL(zck);
 
@@ -122,11 +131,6 @@ int get_tmp_fd(zckCtx *zck) {
         tmpdir = "/tmp/";
     }
     fname = zmalloc(strlen(template) + strlen(tmpdir) + 2);
-    if(fname == NULL) {
-        set_error(zck, "Unable to allocate %lu bytes",
-                  strlen(template) + strlen(tmpdir) + 2);
-        return -1;
-    }
     strncpy(fname, tmpdir, strlen(tmpdir));
     strncpy(fname+strlen(tmpdir), "/", 2);
     strncpy(fname+strlen(tmpdir)+1, template, strlen(template));
@@ -160,10 +164,6 @@ bool import_dict(zckCtx *zck) {
 
     zck_log(ZCK_LOG_DEBUG, "Reading compression dict");
     char *data = zmalloc(size);
-    if(data == NULL) {
-        set_error(zck, "Unable to allocate %lu bytes", size);
-        return false;
-    }
     if(comp_read(zck, data, size, 0) != size) {
         set_error(zck, "Error reading compressed dict");
         return false;
@@ -184,10 +184,6 @@ bool PUBLIC zck_set_soption(zckCtx *zck, zck_soption option, const char *value,
                             size_t length) {
     VALIDATE_BOOL(zck);
     char *data = zmalloc(length);
-    if(data == NULL) {
-        set_error(zck, "Unable to allocate %lu bytes", length);
-        return false;
-    }
     memcpy(data, value, length);
 
     /* Validation options */
@@ -325,10 +321,6 @@ void PUBLIC zck_free(zckCtx **zck) {
 
 zckCtx PUBLIC *zck_create() {
     zckCtx *zck = zmalloc(sizeof(zckCtx));
-    if(zck == NULL) {
-        set_error(NULL, "Unable to allocate %lu bytes", sizeof(zckCtx));
-        return NULL;
-    }
     zck_clear_error(NULL);
     zck->prep_hash_type = -1;
     zck->prep_hdr_size = -1;
index 0a3afad6e7ee0c216b62e1e1f56d6a8eee2dca19..32b4413d2aad19bc4fa58dfc9752a9351a5cef00 100644 (file)
@@ -1,5 +1,6 @@
 #ifndef ZCK_PRIVATE_H
 #define ZCK_PRIVATE_H
+
 #include <stdarg.h>
 #include <stdint.h>
 #include <stdbool.h>
@@ -19,8 +20,6 @@
 #define CHUNK_DEFAULT_MIN 1
 #define CHUNK_DEFAULT_MAX 10485760 // 10MB
 
-#define zmalloc(x) calloc(1, x)
-
 #define PUBLIC __attribute__((visibility("default")))
 
 #define zck_log(...) zck_log_wf(__func__, __VA_ARGS__)
@@ -87,6 +86,7 @@
                                         "zckCtx not opened for writing"); \
                                     return NULL; \
                                 }
+
 typedef struct zckComp zckComp;
 typedef zckCtx zckCtx;
 
@@ -293,6 +293,10 @@ int get_tmp_fd()
     __attribute__ ((warn_unused_result));
 bool import_dict(zckCtx *zck)
     __attribute__ ((warn_unused_result));
+void *zmalloc(size_t size)
+    __attribute__ ((warn_unused_result));
+void *zrealloc(void *ptr, size_t size)
+    __attribute__ ((warn_unused_result));
 
 
 /* hash/hash.h */