]> git.ipfire.org Git - thirdparty/libarchive.git/commitdiff
Replace malloc + memset with calloc.
authorJoerg Sonnenberger <joerg@bec.de>
Tue, 6 Dec 2016 14:58:03 +0000 (15:58 +0100)
committerJoerg Sonnenberger <joerg@bec.de>
Tue, 6 Dec 2016 14:58:03 +0000 (15:58 +0100)
25 files changed:
cpio/cpio.c
libarchive/archive_acl.c
libarchive/archive_entry.c
libarchive/archive_openssl_evp_private.h
libarchive/archive_openssl_hmac_private.h
libarchive/archive_read_disk_posix.c
libarchive/archive_read_disk_windows.c
libarchive/archive_read_extract2.c
libarchive/archive_read_open_memory.c
libarchive/archive_read_support_format_ar.c
libarchive/archive_read_support_format_mtree.c
libarchive/archive_read_support_format_rar.c
libarchive/archive_read_support_format_tar.c
libarchive/archive_read_support_format_warc.c
libarchive/archive_write.c
libarchive/archive_write_disk_posix.c
libarchive/archive_write_disk_set_standard_lookup.c
libarchive/archive_write_disk_windows.c
libarchive/archive_write_open_memory.c
libarchive/archive_write_set_format_ar.c
libarchive/archive_write_set_format_cpio_newc.c
libarchive/archive_write_set_format_pax.c
libarchive/archive_write_set_format_shar.c
libarchive/archive_write_set_format_ustar.c
libarchive/archive_write_set_format_v7tar.c

index c11ac163122d560a744058f743eca120903e7cf1..373e6da787f5fc803925c04a732190bd4c1b8f69 100644 (file)
@@ -1324,10 +1324,9 @@ lookup_name(struct cpio *cpio, struct name_cache **name_cache_variable,
 
 
        if (*name_cache_variable == NULL) {
-               *name_cache_variable = malloc(sizeof(struct name_cache));
+               *name_cache_variable = calloc(1, sizeof(struct name_cache));
                if (*name_cache_variable == NULL)
                        lafe_errc(1, ENOMEM, "No more memory");
-               memset(*name_cache_variable, 0, sizeof(struct name_cache));
                (*name_cache_variable)->size = name_cache_size;
        }
 
index bda841714cb096775d1e2b1a410ca3c97c8ed8f3..ff5c90492b95ebd2a122c8c74da485591b2bcb9f 100644 (file)
@@ -296,10 +296,9 @@ acl_new_entry(struct archive_acl *acl,
        }
 
        /* Add a new entry to the end of the list. */
-       ap = (struct archive_acl_entry *)malloc(sizeof(*ap));
+       ap = (struct archive_acl_entry *)calloc(1, sizeof(*ap));
        if (ap == NULL)
                return (NULL);
-       memset(ap, 0, sizeof(*ap));
        if (aq == NULL)
                acl->acl_head = ap;
        else
index 88ce3976d99540455b01a3969fd58ca625301219..b05eb4d2247707a5112f2d434f06bd49ae2c72f0 100644 (file)
@@ -248,10 +248,9 @@ archive_entry_new2(struct archive *a)
 {
        struct archive_entry *entry;
 
-       entry = (struct archive_entry *)malloc(sizeof(*entry));
+       entry = (struct archive_entry *)calloc(1, sizeof(*entry));
        if (entry == NULL)
                return (NULL);
-       memset(entry, 0, sizeof(*entry));
        entry->archive = a;
        return (entry);
 }
index 0e97e2766ed35397e5e060750eee96642dd78d4a..43a3ccc52a1d7779b1dd78d6c638b91ec4690e3c 100644 (file)
 #include <string.h> /* memset */
 static inline EVP_MD_CTX *EVP_MD_CTX_new(void)
 {
-       EVP_MD_CTX *ctx = (EVP_MD_CTX *)malloc(sizeof(EVP_MD_CTX));
-       if (ctx != NULL) {
-               memset(ctx, 0, sizeof(*ctx));
-       }
+       EVP_MD_CTX *ctx = (EVP_MD_CTX *)calloc(1, sizeof(EVP_MD_CTX));
        return ctx;
 }
 
index d4ae0d174c32ed1c70dc616a3acca0f800116243..2deeb5f559009bba5b0526f122f3d1c8db26d0df 100644 (file)
 #include <string.h> /* memset */
 static inline HMAC_CTX *HMAC_CTX_new(void)
 {
-       HMAC_CTX *ctx = (HMAC_CTX *)malloc(sizeof(HMAC_CTX));
-       if (ctx != NULL) {
-               memset(ctx, 0, sizeof(*ctx));
-               HMAC_CTX_init(ctx);
-       }
+       HMAC_CTX *ctx = (HMAC_CTX *)calloc(1, sizeof(HMAC_CTX));
        return ctx;
 }
 
index e856d98b711e6fa67eb95b54ee9244b602e8af2b..157f47202172516d55507c044ac448b3613da01c 100644 (file)
@@ -2063,8 +2063,7 @@ tree_push(struct tree *t, const char *path, int filesystem_id,
 {
        struct tree_entry *te;
 
-       te = malloc(sizeof(*te));
-       memset(te, 0, sizeof(*te));
+       te = calloc(1, sizeof(*te));
        te->next = t->stack;
        te->parent = t->current;
        if (te->parent)
@@ -2122,9 +2121,8 @@ tree_open(const char *path, int symlink_mode, int restore_time)
 {
        struct tree *t;
 
-       if ((t = malloc(sizeof(*t))) == NULL)
+       if ((t = calloc(1, sizeof(*t))) == NULL)
                return (NULL);
-       memset(t, 0, sizeof(*t));
        archive_string_init(&t->path);
        archive_string_ensure(&t->path, 31);
        t->initial_symlink_mode = symlink_mode;
index 1fd158ffd5f452135881e269195994e1c894650e..287f74c2da3d736319eed65481bad2a01dc6f390 100644 (file)
@@ -389,10 +389,9 @@ archive_read_disk_new(void)
 {
        struct archive_read_disk *a;
 
-       a = (struct archive_read_disk *)malloc(sizeof(*a));
+       a = (struct archive_read_disk *)calloc(1, sizeof(*a));
        if (a == NULL)
                return (NULL);
-       memset(a, 0, sizeof(*a));
        a->archive.magic = ARCHIVE_READ_DISK_MAGIC;
        a->archive.state = ARCHIVE_STATE_NEW;
        a->archive.vtable = archive_read_disk_vtable();
@@ -1437,8 +1436,7 @@ tree_push(struct tree *t, const wchar_t *path, const wchar_t *full_path,
 {
        struct tree_entry *te;
 
-       te = malloc(sizeof(*te));
-       memset(te, 0, sizeof(*te));
+       te = calloc(1, sizeof(*te));
        te->next = t->stack;
        te->parent = t->current;
        if (te->parent)
@@ -1507,8 +1505,7 @@ tree_open(const wchar_t *path, int symlink_mode, int restore_time)
 {
        struct tree *t;
 
-       t = malloc(sizeof(*t));
-       memset(t, 0, sizeof(*t));
+       t = calloc(1, sizeof(*t));
        archive_string_init(&(t->full_path));
        archive_string_init(&t->path);
        archive_wstring_ensure(&t->path, 15);
index 7b2c12631dc76f9c7cd841685be9338bc21eff61..4febd8ce056f3a7c2b807319badf7d19af558b73 100644 (file)
@@ -52,12 +52,11 @@ struct archive_read_extract *
 __archive_read_get_extract(struct archive_read *a)
 {
        if (a->extract == NULL) {
-               a->extract = (struct archive_read_extract *)malloc(sizeof(*a->extract));
+               a->extract = (struct archive_read_extract *)calloc(1, sizeof(*a->extract));
                if (a->extract == NULL) {
                        archive_set_error(&a->archive, ENOMEM, "Can't extract");
                        return (NULL);
                }
-               memset(a->extract, 0, sizeof(*a->extract));
                a->cleanup_archive_extract = archive_read_extract_cleanup;
        }
        return (a->extract);
index ff935a708f597bad30cfbabb6612015b70e6d11e..311be47046a2dba541cbd076669591f2d0a81665 100644 (file)
@@ -70,12 +70,11 @@ archive_read_open_memory2(struct archive *a, const void *buff,
 {
        struct read_memory_data *mine;
 
-       mine = (struct read_memory_data *)malloc(sizeof(*mine));
+       mine = (struct read_memory_data *)calloc(1, sizeof(*mine));
        if (mine == NULL) {
                archive_set_error(a, ENOMEM, "No memory");
                return (ARCHIVE_FATAL);
        }
-       memset(mine, 0, sizeof(*mine));
        mine->start = mine->p = (const unsigned char *)buff;
        mine->end = mine->start + size;
        mine->read_size = read_size;
index c766cbaba7a8a3a613df305bbdb6e50e98b2f15b..ff81f5fb770a82de2c741f28cad76e04bd2adf24 100644 (file)
@@ -104,13 +104,12 @@ archive_read_support_format_ar(struct archive *_a)
        archive_check_magic(_a, ARCHIVE_READ_MAGIC,
            ARCHIVE_STATE_NEW, "archive_read_support_format_ar");
 
-       ar = (struct ar *)malloc(sizeof(*ar));
+       ar = (struct ar *)calloc(1, sizeof(*ar));
        if (ar == NULL) {
                archive_set_error(&a->archive, ENOMEM,
                    "Can't allocate ar data");
                return (ARCHIVE_FATAL);
        }
-       memset(ar, 0, sizeof(*ar));
        ar->strtab = NULL;
 
        r = __archive_read_register_format(a,
index 85c655fbbbc66107633cc81e31be09b8946186ab..d0aa84ccaeff8a018ccbf3bba827c789fedb183f 100644 (file)
@@ -229,13 +229,12 @@ archive_read_support_format_mtree(struct archive *_a)
        archive_check_magic(_a, ARCHIVE_READ_MAGIC,
            ARCHIVE_STATE_NEW, "archive_read_support_format_mtree");
 
-       mtree = (struct mtree *)malloc(sizeof(*mtree));
+       mtree = (struct mtree *)calloc(1, sizeof(*mtree));
        if (mtree == NULL) {
                archive_set_error(&a->archive, ENOMEM,
                    "Can't allocate mtree data");
                return (ARCHIVE_FATAL);
        }
-       memset(mtree, 0, sizeof(*mtree));
        mtree->fd = -1;
 
        r = __archive_read_register_format(a, mtree, "mtree",
index f729f173645d6f83a32524c761a749963f391da5..9c9f6f12ec01d5b907d4398d68c58783aeeab428 100644 (file)
@@ -647,13 +647,12 @@ archive_read_support_format_rar(struct archive *_a)
   archive_check_magic(_a, ARCHIVE_READ_MAGIC, ARCHIVE_STATE_NEW,
                       "archive_read_support_format_rar");
 
-  rar = (struct rar *)malloc(sizeof(*rar));
+  rar = (struct rar *)calloc(sizeof(*rar), 1);
   if (rar == NULL)
   {
     archive_set_error(&a->archive, ENOMEM, "Can't allocate rar data");
     return (ARCHIVE_FATAL);
   }
-  memset(rar, 0, sizeof(*rar));
 
        /*
         * Until enough data has been read, we cannot tell about
index 6febc2dd28b45b945693bad4c0689b605f7c9a9d..e572bbde00b1fd32b6bb1ea3b4bbf486264d989c 100644 (file)
@@ -2187,12 +2187,11 @@ gnu_add_sparse_entry(struct archive_read *a, struct tar *tar,
 {
        struct sparse_block *p;
 
-       p = (struct sparse_block *)malloc(sizeof(*p));
+       p = (struct sparse_block *)calloc(1, sizeof(*p));
        if (p == NULL) {
                archive_set_error(&a->archive, ENOMEM, "Out of memory");
                return (ARCHIVE_FATAL);
        }
-       memset(p, 0, sizeof(*p));
        if (tar->sparse_last != NULL)
                tar->sparse_last->next = p;
        else
index deeaa9e6d93df1a19c684da648df03b66c5eb5d2..a287fc2a06b5910fea05b384bac2b5856f54b25c 100644 (file)
@@ -146,12 +146,11 @@ archive_read_support_format_warc(struct archive *_a)
        archive_check_magic(_a, ARCHIVE_READ_MAGIC,
            ARCHIVE_STATE_NEW, "archive_read_support_format_warc");
 
-       if ((w = malloc(sizeof(*w))) == NULL) {
+       if ((w = calloc(1, sizeof(*w))) == NULL) {
                archive_set_error(&a->archive, ENOMEM,
                    "Can't allocate warc data");
                return (ARCHIVE_FATAL);
        }
-       memset(w, 0, sizeof(*w));
 
        r = __archive_read_register_format(
                a, w, "warc",
index e3fa3357ba7b3d6b9dc3fd14f42312ff24b41aed..0697db1dd9190bff373e9c73416f6dd5cfc9f25f 100644 (file)
@@ -109,10 +109,9 @@ archive_write_new(void)
        struct archive_write *a;
        unsigned char *nulls;
 
-       a = (struct archive_write *)malloc(sizeof(*a));
+       a = (struct archive_write *)calloc(1, sizeof(*a));
        if (a == NULL)
                return (NULL);
-       memset(a, 0, sizeof(*a));
        a->archive.magic = ARCHIVE_WRITE_MAGIC;
        a->archive.state = ARCHIVE_STATE_NEW;
        a->archive.vtable = archive_write_vtable();
@@ -126,12 +125,11 @@ archive_write_new(void)
 
        /* Initialize a block of nulls for padding purposes. */
        a->null_length = 1024;
-       nulls = (unsigned char *)malloc(a->null_length);
+       nulls = (unsigned char *)calloc(1, a->null_length);
        if (nulls == NULL) {
                free(a);
                return (NULL);
        }
-       memset(nulls, 0, a->null_length);
        a->nulls = nulls;
        return (&a->archive);
 }
index afcadbbe2571780d5c0519de493bb606d2e29580..5fca75d8fdb8ad11a9c0139c7a92c33284fb0d98 100644 (file)
@@ -1779,10 +1779,9 @@ archive_write_disk_new(void)
 {
        struct archive_write_disk *a;
 
-       a = (struct archive_write_disk *)malloc(sizeof(*a));
+       a = (struct archive_write_disk *)calloc(1, sizeof(*a));
        if (a == NULL)
                return (NULL);
-       memset(a, 0, sizeof(*a));
        a->archive.magic = ARCHIVE_WRITE_DISK_MAGIC;
        /* We're ready to write a header immediately. */
        a->archive.state = ARCHIVE_STATE_HEADER;
index 3b868fbad195e2b4e7f0090b238b5db6baa447b4..5c766d75dd01ca070246d4e70c994a53d1c160e1 100644 (file)
@@ -84,15 +84,13 @@ static void cleanup(void *);
 int
 archive_write_disk_set_standard_lookup(struct archive *a)
 {
-       struct bucket *ucache = malloc(cache_size * sizeof(struct bucket));
-       struct bucket *gcache = malloc(cache_size * sizeof(struct bucket));
+       struct bucket *ucache = calloc(cache_size, sizeof(struct bucket));
+       struct bucket *gcache = calloc(cache_size, sizeof(struct bucket));
        if (ucache == NULL || gcache == NULL) {
                free(ucache);
                free(gcache);
                return (ARCHIVE_FATAL);
        }
-       memset(ucache, 0, cache_size * sizeof(struct bucket));
-       memset(gcache, 0, cache_size * sizeof(struct bucket));
        archive_write_disk_set_group_lookup(a, gcache, lookup_gid, cleanup);
        archive_write_disk_set_user_lookup(a, ucache, lookup_uid, cleanup);
        return (ARCHIVE_OK);
index 4e7a664a2bc9bda37c30e7094355ef20d87da436..94b016edf01ac76717b832b557ce18eb6815c761 100644 (file)
@@ -1221,10 +1221,9 @@ archive_write_disk_new(void)
 {
        struct archive_write_disk *a;
 
-       a = (struct archive_write_disk *)malloc(sizeof(*a));
+       a = (struct archive_write_disk *)calloc(1, sizeof(*a));
        if (a == NULL)
                return (NULL);
-       memset(a, 0, sizeof(*a));
        a->archive.magic = ARCHIVE_WRITE_DISK_MAGIC;
        /* We're ready to write a header immediately. */
        a->archive.state = ARCHIVE_STATE_HEADER;
index 4f8d679e582fc20f4758cfbe5b8d7aab2cbc88fb..ea6ae0ac5244f21488127c3f7d25f95a20e93abd 100644 (file)
@@ -53,12 +53,11 @@ archive_write_open_memory(struct archive *a, void *buff, size_t buffSize, size_t
 {
        struct write_memory_data *mine;
 
-       mine = (struct write_memory_data *)malloc(sizeof(*mine));
+       mine = (struct write_memory_data *)calloc(1, sizeof(*mine));
        if (mine == NULL) {
                archive_set_error(a, ENOMEM, "No memory");
                return (ARCHIVE_FATAL);
        }
-       memset(mine, 0, sizeof(*mine));
        mine->buff = buff;
        mine->size = buffSize;
        mine->client_size = used;
index 9f17564c34c34b3e5de96099a3103c8a664739f9..c9771d81a128cd245ad444e6fbab0dda7c49d045 100644 (file)
@@ -126,12 +126,11 @@ archive_write_set_format_ar(struct archive_write *a)
        if (a->format_free != NULL)
                (a->format_free)(a);
 
-       ar = (struct ar_w *)malloc(sizeof(*ar));
+       ar = (struct ar_w *)calloc(1, sizeof(*ar));
        if (ar == NULL) {
                archive_set_error(&a->archive, ENOMEM, "Can't allocate ar data");
                return (ARCHIVE_FATAL);
        }
-       memset(ar, 0, sizeof(*ar));
        a->format_data = ar;
 
        a->format_name = "ar";
index 54b5576ca25e17439615adbe534e681405a2fdc0..957f1a333a6ac98ddaf9bf3251658a7128abe702 100644 (file)
@@ -116,12 +116,11 @@ archive_write_set_format_cpio_newc(struct archive *_a)
        if (a->format_free != NULL)
                (a->format_free)(a);
 
-       cpio = (struct cpio *)malloc(sizeof(*cpio));
+       cpio = (struct cpio *)calloc(1, sizeof(*cpio));
        if (cpio == NULL) {
                archive_set_error(&a->archive, ENOMEM, "Can't allocate cpio data");
                return (ARCHIVE_FATAL);
        }
-       memset(cpio, 0, sizeof(*cpio));
        a->format_data = cpio;
        a->format_name = "cpio";
        a->format_options = archive_write_newc_options;
index 30fd6df1154f14cbfeae86908b3e9dfc18dca4d1..386d7451d91ddc2999b0b6daf007ac14f0d55f2f 100644 (file)
@@ -127,13 +127,12 @@ archive_write_set_format_pax(struct archive *_a)
        if (a->format_free != NULL)
                (a->format_free)(a);
 
-       pax = (struct pax *)malloc(sizeof(*pax));
+       pax = (struct pax *)calloc(1, sizeof(*pax));
        if (pax == NULL) {
                archive_set_error(&a->archive, ENOMEM,
                    "Can't allocate pax data");
                return (ARCHIVE_FATAL);
        }
-       memset(pax, 0, sizeof(*pax));
        a->format_data = pax;
        a->format_name = "pax";
        a->format_options = archive_write_pax_options;
index c033fb32f7efdb35474fe8d137ca34f99be85461..5be310a0781fcf3613acf90817110fc6c1875208 100644 (file)
@@ -113,12 +113,11 @@ archive_write_set_format_shar(struct archive *_a)
        if (a->format_free != NULL)
                (a->format_free)(a);
 
-       shar = (struct shar *)malloc(sizeof(*shar));
+       shar = (struct shar *)calloc(1, sizeof(*shar));
        if (shar == NULL) {
                archive_set_error(&a->archive, ENOMEM, "Can't allocate shar data");
                return (ARCHIVE_FATAL);
        }
-       memset(shar, 0, sizeof(*shar));
        archive_string_init(&shar->work);
        archive_string_init(&shar->quoted_name);
        a->format_data = shar;
index b475f45f1457034a40f58c21856edab9237e8de5..c54aeabdb198a08c291b41d07cbb0134ffc5e25f 100644 (file)
@@ -184,13 +184,12 @@ archive_write_set_format_ustar(struct archive *_a)
                return (ARCHIVE_FATAL);
        }
 
-       ustar = (struct ustar *)malloc(sizeof(*ustar));
+       ustar = (struct ustar *)calloc(1, sizeof(*ustar));
        if (ustar == NULL) {
                archive_set_error(&a->archive, ENOMEM,
                    "Can't allocate ustar data");
                return (ARCHIVE_FATAL);
        }
-       memset(ustar, 0, sizeof(*ustar));
        a->format_data = ustar;
        a->format_name = "ustar";
        a->format_options = archive_write_ustar_options;
index a6ca158df7db13758f64bafb19acea034e59ebe9..62b15229444c46272d8efd84cbc5a71e4fbcbb00 100644 (file)
@@ -161,13 +161,12 @@ archive_write_set_format_v7tar(struct archive *_a)
                return (ARCHIVE_FATAL);
        }
 
-       v7tar = (struct v7tar *)malloc(sizeof(*v7tar));
+       v7tar = (struct v7tar *)calloc(1, sizeof(*v7tar));
        if (v7tar == NULL) {
                archive_set_error(&a->archive, ENOMEM,
                    "Can't allocate v7tar data");
                return (ARCHIVE_FATAL);
        }
-       memset(v7tar, 0, sizeof(*v7tar));
        a->format_data = v7tar;
        a->format_name = "tar (non-POSIX)";
        a->format_options = archive_write_v7tar_options;