]> git.ipfire.org Git - thirdparty/libarchive.git/commitdiff
Miscellaneous code cleanup (#2285)
authorDag-Erling Smørgrav <des@des.no>
Fri, 4 Oct 2024 15:45:58 +0000 (17:45 +0200)
committerGitHub <noreply@github.com>
Fri, 4 Oct 2024 15:45:58 +0000 (08:45 -0700)
This fixes various code quality issues I encountered while chasing a
memory leak reported by test automation. I failed to reproduce the
memory leak, but I hope you find this useful nonetheless.

95 files changed:
configure.ac
cpio/cmdline.c
libarchive/archive_acl.c
libarchive/archive_entry.c
libarchive/archive_entry_sparse.c
libarchive/archive_entry_xattr.c
libarchive/archive_match.c
libarchive/archive_openssl_evp_private.h
libarchive/archive_openssl_hmac_private.h
libarchive/archive_ppmd7.c
libarchive/archive_ppmd8.c
libarchive/archive_read.c
libarchive/archive_read_append_filter.c
libarchive/archive_read_disk_posix.c
libarchive/archive_read_disk_windows.c
libarchive/archive_read_extract2.c
libarchive/archive_read_open_fd.c
libarchive/archive_read_open_file.c
libarchive/archive_read_open_filename.c
libarchive/archive_read_open_memory.c
libarchive/archive_read_support_filter_bzip2.c
libarchive/archive_read_support_filter_compress.c
libarchive/archive_read_support_filter_gzip.c
libarchive/archive_read_support_filter_lz4.c
libarchive/archive_read_support_filter_lzop.c
libarchive/archive_read_support_filter_program.c
libarchive/archive_read_support_filter_rpm.c
libarchive/archive_read_support_filter_uu.c
libarchive/archive_read_support_filter_xz.c
libarchive/archive_read_support_filter_zstd.c
libarchive/archive_read_support_format_7zip.c
libarchive/archive_read_support_format_ar.c
libarchive/archive_read_support_format_cab.c
libarchive/archive_read_support_format_cpio.c
libarchive/archive_read_support_format_iso9660.c
libarchive/archive_read_support_format_lha.c
libarchive/archive_read_support_format_mtree.c
libarchive/archive_read_support_format_rar.c
libarchive/archive_read_support_format_rar5.c
libarchive/archive_read_support_format_raw.c
libarchive/archive_read_support_format_tar.c
libarchive/archive_read_support_format_xar.c
libarchive/archive_read_support_format_zip.c
libarchive/archive_string.c
libarchive/archive_util.c
libarchive/archive_write.c
libarchive/archive_write_add_filter_b64encode.c
libarchive/archive_write_add_filter_bzip2.c
libarchive/archive_write_add_filter_compress.c
libarchive/archive_write_add_filter_gzip.c
libarchive/archive_write_add_filter_uuencode.c
libarchive/archive_write_add_filter_xz.c
libarchive/archive_write_add_filter_zstd.c
libarchive/archive_write_disk_posix.c
libarchive/archive_write_disk_windows.c
libarchive/archive_write_open_fd.c
libarchive/archive_write_open_file.c
libarchive/archive_write_open_filename.c
libarchive/archive_write_open_memory.c
libarchive/archive_write_set_format_ar.c
libarchive/archive_write_set_format_cpio_binary.c
libarchive/archive_write_set_format_cpio_newc.c
libarchive/archive_write_set_format_cpio_odc.c
libarchive/archive_write_set_format_gnutar.c
libarchive/archive_write_set_format_pax.c
libarchive/archive_write_set_format_raw.c
libarchive/archive_write_set_format_shar.c
libarchive/archive_write_set_format_ustar.c
libarchive/archive_write_set_format_v7tar.c
libarchive/archive_write_set_format_zip.c
libarchive/test/test_archive_read_multiple_data_objects.c
libarchive/test/test_archive_string.c
libarchive/test/test_archive_write_add_filter_by_name.c
libarchive/test/test_read_format_xar.c
libarchive/test/test_read_format_zip_nested.c
libarchive/test/test_read_truncated_filter.c
libarchive/test/test_tar_large.c
libarchive/test/test_write_filter_b64encode.c
libarchive/test/test_write_filter_bzip2.c
libarchive/test/test_write_filter_compress.c
libarchive/test/test_write_filter_gzip.c
libarchive/test/test_write_filter_gzip_timestamp.c
libarchive/test/test_write_filter_lrzip.c
libarchive/test/test_write_filter_lz4.c
libarchive/test/test_write_filter_lzip.c
libarchive/test/test_write_filter_lzma.c
libarchive/test/test_write_filter_lzop.c
libarchive/test/test_write_filter_uuencode.c
libarchive/test/test_write_filter_xz.c
libarchive/test/test_write_filter_zstd.c
libarchive/test/test_write_format_iso9660_filename.c
libarchive/test/test_write_format_zip_large.c
tar/creation_set.c
test_utils/test_common.h
test_utils/test_main.c

index c4d79ab6a5563b0ff6099b7e2fb77f693f7e611f..1d7c8da572064a695e90df4a627ff8be5d737e3b 100644 (file)
@@ -367,6 +367,7 @@ AC_CHECK_HEADERS([sys/param.h sys/poll.h sys/richacl.h])
 AC_CHECK_HEADERS([sys/select.h sys/statfs.h sys/statvfs.h sys/sysmacros.h])
 AC_CHECK_HEADERS([sys/time.h sys/utime.h sys/utsname.h sys/vfs.h sys/xattr.h])
 AC_CHECK_HEADERS([time.h unistd.h utime.h wchar.h wctype.h])
+AC_CHECK_TYPE([suseconds_t])
 AC_CHECK_HEADERS([windows.h])
 # check windows.h first; the other headers require it.
 AC_CHECK_HEADERS([wincrypt.h winioctl.h],[],[],
index 0f26c51739b236d51ef455842d4b0de458e2dd60..60ca9c67b0288a24b45856f580f7253f74ea7437 100644 (file)
@@ -350,7 +350,7 @@ owner_parse(const char *spec, struct cpio_owner *owner, const char **errmsg)
                char *user;
                struct passwd *pwent;
 
-               user = (char *)malloc(ue - u + 1);
+               user = malloc(ue - u + 1);
                if (user == NULL)
                        goto alloc_error;
                memcpy(user, u, ue - u);
index 77d99480f96bd31541dc861db8f5110e328d9c16..bbb085afe7afa8615f5a0a0ff1482537d7167938 100644 (file)
@@ -56,7 +56,7 @@ static int    archive_acl_add_entry_len_l(struct archive_acl *acl,
                    int type, int permset, int tag, int id, const char *name,
                    size_t len, struct archive_string_conv *sc);
 static int     archive_acl_text_want_type(struct archive_acl *acl, int flags);
-static ssize_t archive_acl_text_len(struct archive_acl *acl, int want_type,
+static size_t  archive_acl_text_len(struct archive_acl *acl, int want_type,
                    int flags, int wide, struct archive *a,
                    struct archive_string_conv *sc);
 static int     isint_w(const wchar_t *start, const wchar_t *end, int *result);
@@ -346,7 +346,7 @@ acl_new_entry(struct archive_acl *acl,
        }
 
        /* Add a new entry to the end of the list. */
-       ap = (struct archive_acl_entry *)calloc(1, sizeof(*ap));
+       ap = calloc(1, sizeof(*ap));
        if (ap == NULL)
                return (NULL);
        if (aq == NULL)
@@ -528,14 +528,14 @@ archive_acl_text_want_type(struct archive_acl *acl, int flags)
 /*
  * Calculate ACL text string length
  */
-static ssize_t
+static size_t
 archive_acl_text_len(struct archive_acl *acl, int want_type, int flags,
     int wide, struct archive *a, struct archive_string_conv *sc) {
        struct archive_acl_entry *ap;
        const char *name;
        const wchar_t *wname;
        int count, idlen, tmp, r;
-       ssize_t length;
+       size_t length;
        size_t len;
 
        count = 0;
@@ -664,7 +664,7 @@ archive_acl_to_text_w(struct archive_acl *acl, ssize_t *text_len, int flags,
     struct archive *a)
 {
        int count;
-       ssize_t length;
+       size_t length;
        size_t len;
        const wchar_t *wname;
        const wchar_t *prefix;
@@ -693,7 +693,7 @@ archive_acl_to_text_w(struct archive_acl *acl, ssize_t *text_len, int flags,
                separator = L'\n';
 
        /* Now, allocate the string and actually populate it. */
-       wp = ws = (wchar_t *)malloc(length * sizeof(wchar_t));
+       wp = ws = malloc(length * sizeof(*wp));
        if (wp == NULL) {
                if (errno == ENOMEM)
                        __archive_errx(1, "No memory");
@@ -755,7 +755,7 @@ archive_acl_to_text_w(struct archive_acl *acl, ssize_t *text_len, int flags,
 
        len = wcslen(ws);
 
-       if ((ssize_t)len > (length - 1))
+       if (len > length - 1)
                __archive_errx(1, "Buffer overrun");
 
        if (text_len != NULL)
@@ -897,7 +897,7 @@ archive_acl_to_text_l(struct archive_acl *acl, ssize_t *text_len, int flags,
     struct archive_string_conv *sc)
 {
        int count;
-       ssize_t length;
+       size_t length;
        size_t len;
        const char *name;
        const char *prefix;
@@ -926,7 +926,7 @@ archive_acl_to_text_l(struct archive_acl *acl, ssize_t *text_len, int flags,
                separator = '\n';
 
        /* Now, allocate the string and actually populate it. */
-       p = s = (char *)malloc(length * sizeof(char));
+       p = s = malloc(length * sizeof(*p));
        if (p == NULL) {
                if (errno == ENOMEM)
                        __archive_errx(1, "No memory");
@@ -990,7 +990,7 @@ archive_acl_to_text_l(struct archive_acl *acl, ssize_t *text_len, int flags,
 
        len = strlen(s);
 
-       if ((ssize_t)len > (length - 1))
+       if (len > length - 1)
                __archive_errx(1, "Buffer overrun");
 
        if (text_len != NULL)
index f68fee65d521cba6ec35f85d85eb4dad0ce68337..4ebfc5fa6323b8dbcb2f8be9d4b2858135733eb3 100644 (file)
@@ -263,7 +263,7 @@ archive_entry_new2(struct archive *a)
 {
        struct archive_entry *entry;
 
-       entry = (struct archive_entry *)calloc(1, sizeof(*entry));
+       entry = calloc(1, sizeof(*entry));
        if (entry == NULL)
                return (NULL);
        entry->archive = a;
@@ -2095,7 +2095,7 @@ ae_fflagstostr(unsigned long bitset, unsigned long bitclear)
 
        if (length == 0)
                return (NULL);
-       string = (char *)malloc(length);
+       string = malloc(length);
        if (string == NULL)
                return (NULL);
 
index b81684d1873042c863d908166297bb324f705ec8..c430896119fb8444b638e5279de206a581a876c9 100644 (file)
@@ -76,7 +76,7 @@ archive_entry_sparse_add_entry(struct archive_entry *entry,
                }
        }
 
-       if ((sp = (struct ae_sparse *)malloc(sizeof(*sp))) == NULL)
+       if ((sp = malloc(sizeof(*sp))) == NULL)
                /* XXX Error XXX */
                return;
 
index 14848a5ab2c4a2a04c70535fea0ca9d046dcd06f..b92e1878bc43d566ac0a80b35d13ed41e9d1fbd2 100644 (file)
@@ -90,7 +90,7 @@ archive_entry_xattr_add_entry(struct archive_entry *entry,
 {
        struct ae_xattr *xp;
 
-       if ((xp = (struct ae_xattr *)malloc(sizeof(struct ae_xattr))) == NULL)
+       if ((xp = malloc(sizeof(struct ae_xattr))) == NULL)
                __archive_errx(1, "Out of memory");
 
        if ((xp->name = strdup(name)) == NULL)
index 3ab8eda360386b2df9bc0c4ae3a3d5da0f419b23..446417a9a2d45e79d52c7aa9f73979b28e02bbe5 100644 (file)
@@ -220,7 +220,7 @@ archive_match_new(void)
 {
        struct archive_match *a;
 
-       a = (struct archive_match *)calloc(1, sizeof(*a));
+       a = calloc(1, sizeof(*a));
        if (a == NULL)
                return (NULL);
        a->archive.magic = ARCHIVE_MATCH_MAGIC;
index 8ac4772808e6f4d42fc66dd638aa2cb6b6a8e9d1..d5ba7b0d60db30712e1b87e8011ab182425fce05 100644 (file)
@@ -39,7 +39,7 @@
 #include <string.h> /* memset */
 static inline EVP_MD_CTX *EVP_MD_CTX_new(void)
 {
-       EVP_MD_CTX *ctx = (EVP_MD_CTX *)calloc(1, sizeof(EVP_MD_CTX));
+       EVP_MD_CTX *ctx = calloc(1, sizeof(EVP_MD_CTX));
        return ctx;
 }
 
index 25c8dda654fcb3db0997e409f531bf144c7d3dcc..8ed76260dde996e4e7302c327777e1acd0b7353b 100644 (file)
@@ -39,7 +39,7 @@
 #include <string.h> /* memset */
 static inline HMAC_CTX *HMAC_CTX_new(void)
 {
-       HMAC_CTX *ctx = (HMAC_CTX *)calloc(1, sizeof(HMAC_CTX));
+       HMAC_CTX *ctx = calloc(1, sizeof(HMAC_CTX));
        return ctx;
 }
 
index cc3f778203f9dce5e7f84dd49d522035e1c51833..30124f1743e5c6dbaaef6db99b34cddcf4e4f9bb 100644 (file)
@@ -138,7 +138,7 @@ static Bool Ppmd7_Alloc(CPpmd7 *p, UInt32 size)
       #else
         4 - (size & 3);
       #endif
-    if ((p->Base = (Byte *)malloc(p->AlignOffset + size
+    if ((p->Base = malloc(p->AlignOffset + size
         #ifndef PPMD_32BIT
         + UNIT_SIZE
         #endif
index bae5970957115648017bb2815b11c14269529308..2fb7f7141c36f3db248b1a233af1dc51cbfbab39 100644 (file)
@@ -107,7 +107,7 @@ Bool Ppmd8_Alloc(CPpmd8 *p, UInt32 size)
       #else
         4 - (size & 3);
       #endif
-    if ((p->Base = (Byte *)malloc(p->AlignOffset + size)) == 0)
+    if ((p->Base = malloc(p->AlignOffset + size)) == 0)
       return False;
     p->Size = size;
   }
index 1fa35853c55837074221a6ca2371562f96ba5b9f..822c534b868a9e89318476fadd53ee379a77067e 100644 (file)
@@ -92,7 +92,7 @@ archive_read_new(void)
 {
        struct archive_read *a;
 
-       a = (struct archive_read *)calloc(1, sizeof(*a));
+       a = calloc(1, sizeof(*a));
        if (a == NULL)
                return (NULL);
        a->archive.magic = ARCHIVE_READ_MAGIC;
@@ -582,7 +582,7 @@ choose_filters(struct archive_read *a)
                }
 
                filter
-                   = (struct archive_read_filter *)calloc(1, sizeof(*filter));
+                   = calloc(1, sizeof(*filter));
                if (filter == NULL)
                        return (ARCHIVE_FATAL);
                filter->bidder = best_bidder;
@@ -1451,7 +1451,7 @@ __archive_read_filter_ahead(struct archive_read_filter *filter,
                                        s = t;
                                }
                                /* Now s >= min, so allocate a new buffer. */
-                               p = (char *)malloc(s);
+                               p = malloc(s);
                                if (p == NULL) {
                                        archive_set_error(
                                                &filter->archive->archive,
index 59ea5c4422dc7c55a82b8a34b655bb09bd6c495c..a3986e9b6e886cf51d0dae34958829141e1540c5 100644 (file)
@@ -123,8 +123,7 @@ archive_read_append_filter(struct archive *_a, int code)
       return (ARCHIVE_FATAL);
     }
 
-    filter
-        = (struct archive_read_filter *)calloc(1, sizeof(*filter));
+    filter = calloc(1, sizeof(*filter));
     if (filter == NULL)
     {
       archive_set_error(&a->archive, ENOMEM, "Out of memory");
@@ -180,8 +179,7 @@ archive_read_append_filter_program_signature(struct archive *_a,
     return (ARCHIVE_FATAL);
   }
 
-  filter
-      = (struct archive_read_filter *)calloc(1, sizeof(*filter));
+  filter = calloc(1, sizeof(*filter));
   if (filter == NULL)
   {
     archive_set_error(&a->archive, ENOMEM, "Out of memory");
index 76a4fa44de727c97b9e275dd56c94d6e7822b81a..09965eb98a2ebcd9c806ed457f2dc394f198d2b3 100644 (file)
@@ -451,7 +451,7 @@ archive_read_disk_new(void)
 {
        struct archive_read_disk *a;
 
-       a = (struct archive_read_disk *)calloc(1, sizeof(*a));
+       a = calloc(1, sizeof(*a));
        if (a == NULL)
                return (NULL);
        a->archive.magic = ARCHIVE_READ_DISK_MAGIC;
index 285747ea91e0694ebcc3ea714569d268e6466ee7..feb870b1195e7f38a7819ec40ffc6d0ee4b5efe8 100644 (file)
@@ -538,7 +538,7 @@ archive_read_disk_new(void)
 {
        struct archive_read_disk *a;
 
-       a = (struct archive_read_disk *)calloc(1, sizeof(*a));
+       a = calloc(1, sizeof(*a));
        if (a == NULL)
                return (NULL);
        a->archive.magic = ARCHIVE_READ_DISK_MAGIC;
@@ -2473,7 +2473,7 @@ setup_sparse_from_disk(struct archive_read_disk *a,
        range.FileOffset.QuadPart = 0;
        range.Length.QuadPart = entry_size;
        outranges_size = 2048;
-       outranges = (FILE_ALLOCATED_RANGE_BUFFER *)malloc(outranges_size);
+       outranges = malloc(outranges_size);
        if (outranges == NULL) {
                archive_set_error(&a->archive, ENOMEM,
                        "Couldn't allocate memory");
index e11cac1590e9744a180276c819b6991dfb3abcd9..7cf38c301176f04d5ee388167af6e14cda12eee5 100644 (file)
@@ -51,7 +51,7 @@ struct archive_read_extract *
 __archive_read_get_extract(struct archive_read *a)
 {
        if (a->extract == NULL) {
-               a->extract = (struct archive_read_extract *)calloc(1, sizeof(*a->extract));
+               a->extract = calloc(1, sizeof(*a->extract));
                if (a->extract == NULL) {
                        archive_set_error(&a->archive, ENOMEM, "Can't extract");
                        return (NULL);
index 3ee2423d300e3b72d51bcbba239e33dc7347820f..debfde2086872f51de981dada9a398390a80544e 100644 (file)
@@ -74,7 +74,7 @@ archive_read_open_fd(struct archive *a, int fd, size_t block_size)
                return (ARCHIVE_FATAL);
        }
 
-       mine = (struct read_fd_data *)calloc(1, sizeof(*mine));
+       mine = calloc(1, sizeof(*mine));
        b = malloc(block_size);
        if (mine == NULL || b == NULL) {
                archive_set_error(a, ENOMEM, "No memory");
index dcf1d46985699ee83f593f2ed925e3674a56f862..cf49ebd8fc9a29a1aaaf22a7bc2bb4f244e95f38 100644 (file)
@@ -69,7 +69,7 @@ archive_read_open_FILE(struct archive *a, FILE *f)
        void *b;
 
        archive_clear_error(a);
-       mine = (struct read_FILE_data *)malloc(sizeof(*mine));
+       mine = malloc(sizeof(*mine));
        b = malloc(block_size);
        if (mine == NULL || b == NULL) {
                archive_set_error(a, ENOMEM, "No memory");
index dd2e16022844b7dd2122577cac3800d089ab8aaf..8def020fff389af782da15a8b85a3528f27a9149 100644 (file)
@@ -122,7 +122,7 @@ archive_read_open_filenames(struct archive *a, const char **filenames,
        {
                if (filename == NULL)
                        filename = "";
-               mine = (struct read_file_data *)calloc(1,
+               mine = calloc(1,
                        sizeof(*mine) + strlen(filename));
                if (mine == NULL)
                        goto no_memory;
@@ -175,7 +175,7 @@ archive_read_open_filenames_w(struct archive *a, const wchar_t **wfilenames,
        {
                if (wfilename == NULL)
                        wfilename = L"";
-               mine = (struct read_file_data *)calloc(1,
+               mine = calloc(1,
                        sizeof(*mine) + wcslen(wfilename) * sizeof(wchar_t));
                if (mine == NULL)
                        goto no_memory;
index a057ce6438904be0a5b62d59edc24abf12680ad8..460bb5ae6a4d230bace4753306138be2985a669e 100644 (file)
@@ -69,7 +69,7 @@ archive_read_open_memory2(struct archive *a, const void *buff,
 {
        struct read_memory_data *mine;
 
-       mine = (struct read_memory_data *)calloc(1, sizeof(*mine));
+       mine = calloc(1, sizeof(*mine));
        if (mine == NULL) {
                archive_set_error(a, ENOMEM, "No memory");
                return (ARCHIVE_FATAL);
index 0392d450a2031eaaa29cd3c18343bd321a45ad8f..479237c277922ffe47abd6e92de93c3fff35ddfa 100644 (file)
@@ -190,8 +190,8 @@ bzip2_reader_init(struct archive_read_filter *self)
        self->code = ARCHIVE_FILTER_BZIP2;
        self->name = "bzip2";
 
-       state = (struct private_data *)calloc(1, sizeof(*state));
-       out_block = (unsigned char *)malloc(out_block_size);
+       state = calloc(1, sizeof(*state));
+       out_block = malloc(out_block_size);
        if (state == NULL || out_block == NULL) {
                archive_set_error(&self->archive->archive, ENOMEM,
                    "Can't allocate data for bzip2 decompression");
index 29ae72abef7106cc922ab2cb0cadedc67066b232..b6e9816dfee9e3a0c6ba3cc035ed44596552921c 100644 (file)
@@ -217,7 +217,7 @@ compress_bidder_init(struct archive_read_filter *self)
        self->code = ARCHIVE_FILTER_COMPRESS;
        self->name = "compress (.Z)";
 
-       state = (struct private_data *)calloc(1, sizeof(*state));
+       state = calloc(1, sizeof(*state));
        out_block = malloc(out_block_size);
        if (state == NULL || out_block == NULL) {
                free(out_block);
index 152ea9bdbd7c5d401c49bc897700892a02c7ebf4..15b98045b467e014f8a4d4d339a5747ea1ac6b72 100644 (file)
@@ -307,8 +307,8 @@ gzip_bidder_init(struct archive_read_filter *self)
        self->code = ARCHIVE_FILTER_GZIP;
        self->name = "gzip";
 
-       state = (struct private_data *)calloc(1, sizeof(*state));
-       out_block = (unsigned char *)malloc(out_block_size);
+       state = calloc(1, sizeof(*state));
+       out_block = malloc(out_block_size);
        if (state == NULL || out_block == NULL) {
                free(out_block);
                free(state);
index bccf4fb8f82dca9434eaac92ea5cecac6dd7fbd7..8c9777156409827ed4b44d8de91132b47b8bafe2 100644 (file)
@@ -223,7 +223,7 @@ lz4_reader_init(struct archive_read_filter *self)
        self->code = ARCHIVE_FILTER_LZ4;
        self->name = "lz4";
 
-       state = (struct private_data *)calloc(1, sizeof(*state));
+       state = calloc(1, sizeof(*state));
        if (state == NULL) {
                archive_set_error(&self->archive->archive, ENOMEM,
                    "Can't allocate data for lz4 decompression");
@@ -248,7 +248,7 @@ lz4_allocate_out_block(struct archive_read_filter *self)
                out_block_size += 64 * 1024;
        if (state->out_block_size < out_block_size) {
                free(state->out_block);
-               out_block = (unsigned char *)malloc(out_block_size);
+               out_block = malloc(out_block_size);
                state->out_block_size = out_block_size;
                if (out_block == NULL) {
                        archive_set_error(&self->archive->archive, ENOMEM,
@@ -271,7 +271,7 @@ lz4_allocate_out_block_for_legacy(struct archive_read_filter *self)
 
        if (state->out_block_size < out_block_size) {
                free(state->out_block);
-               out_block = (unsigned char *)malloc(out_block_size);
+               out_block = malloc(out_block_size);
                state->out_block_size = out_block_size;
                if (out_block == NULL) {
                        archive_set_error(&self->archive->archive, ENOMEM,
index 0aa85927b4a00043961840257e8ffb5c9575ac16..b0c4bb13e8b372090ec69a205464cf0e5c7da3ea 100644 (file)
@@ -185,7 +185,7 @@ lzop_bidder_init(struct archive_read_filter *self)
        self->code = ARCHIVE_FILTER_LZOP;
        self->name = "lzop";
 
-       state = (struct read_lzop *)calloc(1, sizeof(*state));
+       state = calloc(1, sizeof(*state));
        if (state == NULL) {
                archive_set_error(&self->archive->archive, ENOMEM,
                    "Can't allocate data for lzop decompression");
index 0482c57c18eb00648100624d3cf706c3ab471af7..9e825223b26c0fa3191613b785240514e326f92d 100644 (file)
@@ -139,7 +139,7 @@ archive_read_support_filter_program_signature(struct archive *_a,
        /*
         * Allocate our private state.
         */
-       state = (struct program_bidder *)calloc(1, sizeof (*state));
+       state = calloc(1, sizeof (*state));
        if (state == NULL)
                goto memerr;
        state->cmd = strdup(cmd);
@@ -398,8 +398,8 @@ __archive_read_program(struct archive_read_filter *self, const char *cmd)
        size_t l;
 
        l = strlen(prefix) + strlen(cmd) + 1;
-       state = (struct program_filter *)calloc(1, sizeof(*state));
-       out_buf = (char *)malloc(out_buf_len);
+       state = calloc(1, sizeof(*state));
+       out_buf = malloc(out_buf_len);
        if (state == NULL || out_buf == NULL ||
            archive_string_ensure(&state->description, l) == NULL) {
                archive_set_error(&self->archive->archive, ENOMEM,
index a55bc0cf71e9de98b37c91372a0adb58c6462582..25ace4a25bc9e6a220ff20145cee41bee3e60f72 100644 (file)
@@ -144,7 +144,7 @@ rpm_bidder_init(struct archive_read_filter *self)
        self->code = ARCHIVE_FILTER_RPM;
        self->name = "rpm";
 
-       rpm = (struct rpm *)calloc(1, sizeof(*rpm));
+       rpm = calloc(1, sizeof(*rpm));
        if (rpm == NULL) {
                archive_set_error(&self->archive->archive, ENOMEM,
                    "Can't allocate data for rpm");
index 8d361a4f8e7608f20567b5a3c97aae2494acfef6..d722fe343657e4d2fd9dc627ffd26b12d5c04e7b 100644 (file)
@@ -375,7 +375,7 @@ uudecode_bidder_init(struct archive_read_filter *self)
        self->code = ARCHIVE_FILTER_UU;
        self->name = "uu";
 
-       uudecode = (struct uudecode *)calloc(1, sizeof(*uudecode));
+       uudecode = calloc(1, sizeof(*uudecode));
        out_buff = malloc(OUT_BUFF_SIZE);
        in_buff = malloc(IN_BUFF_SIZE);
        if (uudecode == NULL || out_buff == NULL || in_buff == NULL) {
index e55fb00edb34a036bd377286b44a093e15833fde..dcbf734ecacbb05bbf02ecc1d096f4e067b9d4a6 100644 (file)
@@ -476,8 +476,8 @@ xz_lzma_bidder_init(struct archive_read_filter *self)
        struct private_data *state;
        int ret;
 
-       state = (struct private_data *)calloc(1, sizeof(*state));
-       out_block = (unsigned char *)malloc(out_block_size);
+       state = calloc(1, sizeof(*state));
+       out_block = malloc(out_block_size);
        if (state == NULL || out_block == NULL) {
                archive_set_error(&self->archive->archive, ENOMEM,
                    "Can't allocate data for xz decompression");
index f7326d2430d300a9ab042ea9b35252e2f9572f61..9a1dd71abdf6c4e616d820992c9258be9d88a187 100644 (file)
@@ -175,8 +175,8 @@ zstd_bidder_init(struct archive_read_filter *self)
        self->code = ARCHIVE_FILTER_ZSTD;
        self->name = "zstd";
 
-       state = (struct private_data *)calloc(1, sizeof(*state));
-       out_block = (unsigned char *)malloc(out_block_size);
+       state = calloc(1, sizeof(*state));
+       out_block = malloc(out_block_size);
        dstream = ZSTD_createDStream();
 
        if (state == NULL || out_block == NULL || dstream == NULL) {
index b1e0c91ad1a9fff56a2c220bf77e8d6d5818dd97..fd5792d1663ded42354ecdbb93a36ba4136ec8dc 100644 (file)
@@ -767,29 +767,27 @@ archive_read_format_7zip_read_header(struct archive_read *a,
 
        if (zip_entry->attr & supported_attrs) {
                char *fflags_text, *ptr;
-               /* allocate for "rdonly,hidden,system," */
-               fflags_text = malloc(22 * sizeof(char));
+               /* allocate for ",rdonly,hidden,system" */
+               fflags_text = malloc(22 * sizeof(*fflags_text));
                if (fflags_text != NULL) {
                        ptr = fflags_text; 
-                       if (zip_entry->attr & FILE_ATTRIBUTE_READONLY) { 
-                       strcpy(ptr, "rdonly,"); 
-                       ptr = ptr + 7; 
-               } 
-               if (zip_entry->attr & FILE_ATTRIBUTE_HIDDEN) { 
-                       strcpy(ptr, "hidden,"); 
-                       ptr = ptr + 7; 
-               } 
-               if (zip_entry->attr & FILE_ATTRIBUTE_SYSTEM) { 
-                       strcpy(ptr, "system,"); 
-                       ptr = ptr + 7; 
-               } 
-               if (ptr > fflags_text) { 
-                       /* Delete trailing comma */ 
-                       *(ptr - 1) = '\0'; 
-                       archive_entry_copy_fflags_text(entry, 
-                               fflags_text); 
-               } 
-               free(fflags_text); 
+                       if (zip_entry->attr & FILE_ATTRIBUTE_READONLY) {
+                               strcpy(ptr, ",rdonly");
+                               ptr = ptr + 7;
+                       }
+                       if (zip_entry->attr & FILE_ATTRIBUTE_HIDDEN) {
+                               strcpy(ptr, ",hidden");
+                               ptr = ptr + 7;
+                       }
+                       if (zip_entry->attr & FILE_ATTRIBUTE_SYSTEM) {
+                               strcpy(ptr, ",system");
+                               ptr = ptr + 7;
+                       }
+                       if (ptr > fflags_text) {
+                               archive_entry_copy_fflags_text(entry,
+                                   fflags_text + 1);
+                       }
+                       free(fflags_text);
                }
        }
 
index b0d1ddbc5a0af728674469036cfbe9cad2b5dcbe..6dfe2939d0902c5fb988629a335ffdfb5312ef44 100644 (file)
@@ -103,7 +103,7 @@ 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 *)calloc(1, sizeof(*ar));
+       ar = calloc(1, sizeof(*ar));
        if (ar == NULL) {
                archive_set_error(&a->archive, ENOMEM,
                    "Can't allocate ar data");
@@ -368,7 +368,7 @@ _ar_read_header(struct archive_read *a, struct archive_entry *entry,
                        return (ARCHIVE_FATAL);
                }
                /* Store it in the entry. */
-               p = (char *)malloc(bsd_name_length + 1);
+               p = malloc(bsd_name_length + 1);
                if (p == NULL) {
                        archive_set_error(&a->archive, ENOMEM,
                            "Can't allocate fname buffer");
index 4ed088d43c4d26c0ad51eed99647d3166f97a301..e012248a5bc2bf7b09f9834520dc35879709b87d 100644 (file)
@@ -356,7 +356,7 @@ archive_read_support_format_cab(struct archive *_a)
        archive_check_magic(_a, ARCHIVE_READ_MAGIC,
            ARCHIVE_STATE_NEW, "archive_read_support_format_cab");
 
-       cab = (struct cab *)calloc(1, sizeof(*cab));
+       cab = calloc(1, sizeof(*cab));
        if (cab == NULL) {
                archive_set_error(&a->archive, ENOMEM,
                    "Can't allocate CAB data");
@@ -717,7 +717,7 @@ cab_read_header(struct archive_read *a)
        /*
         * Read CFFOLDER.
         */
-       hd->folder_array = (struct cffolder *)calloc(
+       hd->folder_array = calloc(
            hd->folder_count, sizeof(struct cffolder));
        if (hd->folder_array == NULL)
                goto nomem;
@@ -780,7 +780,7 @@ cab_read_header(struct archive_read *a)
                cab->cab_offset += skip;
        }
        /* Allocate memory for CFDATA */
-       hd->file_array = (struct cffile *)calloc(
+       hd->file_array = calloc(
            hd->file_count, sizeof(struct cffile));
        if (hd->file_array == NULL)
                goto nomem;
@@ -1412,7 +1412,7 @@ cab_read_ahead_cfdata_deflate(struct archive_read *a, ssize_t *avail)
        if (cab->uncompressed_buffer == NULL) {
                cab->uncompressed_buffer_size = 0x8000;
                cab->uncompressed_buffer
-                   = (unsigned char *)malloc(cab->uncompressed_buffer_size);
+                   = malloc(cab->uncompressed_buffer_size);
                if (cab->uncompressed_buffer == NULL) {
                        archive_set_error(&a->archive, ENOMEM,
                            "No memory for CAB reader");
@@ -1641,7 +1641,7 @@ cab_read_ahead_cfdata_lzx(struct archive_read *a, ssize_t *avail)
        if (cab->uncompressed_buffer == NULL) {
                cab->uncompressed_buffer_size = 0x8000;
                cab->uncompressed_buffer
-                   = (unsigned char *)malloc(cab->uncompressed_buffer_size);
+                   = malloc(cab->uncompressed_buffer_size);
                if (cab->uncompressed_buffer == NULL) {
                        archive_set_error(&a->archive, ENOMEM,
                            "No memory for CAB reader");
index 69752cbb0cacf55a7d589ab5611280550bbd29c4..42a89c1b69c45f170e895d26e5c25f7a2e534f68 100644 (file)
@@ -228,7 +228,7 @@ archive_read_support_format_cpio(struct archive *_a)
        archive_check_magic(_a, ARCHIVE_READ_MAGIC,
            ARCHIVE_STATE_NEW, "archive_read_support_format_cpio");
 
-       cpio = (struct cpio *)calloc(1, sizeof(*cpio));
+       cpio = calloc(1, sizeof(*cpio));
        if (cpio == NULL) {
                archive_set_error(&a->archive, ENOMEM, "Can't allocate cpio data");
                return (ARCHIVE_FATAL);
@@ -1088,7 +1088,7 @@ record_hardlink(struct archive_read *a,
                }
        }
 
-       le = (struct links_entry *)malloc(sizeof(struct links_entry));
+       le = malloc(sizeof(struct links_entry));
        if (le == NULL) {
                archive_set_error(&a->archive,
                    ENOMEM, "Out of memory adding file to list");
index 951afb6037e577b06e5b47d9a365bb0d4bae172c..baf265f462293596f15e957f7f87c5ba30b7c792 100644 (file)
@@ -463,7 +463,7 @@ archive_read_support_format_iso9660(struct archive *_a)
        archive_check_magic(_a, ARCHIVE_READ_MAGIC,
            ARCHIVE_STATE_NEW, "archive_read_support_format_iso9660");
 
-       iso9660 = (struct iso9660 *)calloc(1, sizeof(*iso9660));
+       iso9660 = calloc(1, sizeof(*iso9660));
        if (iso9660 == NULL) {
                archive_set_error(&a->archive, ENOMEM,
                    "Can't allocate iso9660 data");
@@ -1905,7 +1905,7 @@ parse_file_info(struct archive_read *a, struct file_info *parent,
        }
 
        /* Create a new file entry and copy data from the ISO dir record. */
-       file = (struct file_info *)calloc(1, sizeof(*file));
+       file = calloc(1, sizeof(*file));
        if (file == NULL) {
                archive_set_error(&a->archive, ENOMEM,
                    "No memory for file entry");
index e417baad10a6ba9f5e46d9ed1a53a4c14ac49637..c7cbad272ead26de677b89a756571486390f0127 100644 (file)
@@ -265,7 +265,7 @@ archive_read_support_format_lha(struct archive *_a)
        archive_check_magic(_a, ARCHIVE_READ_MAGIC,
            ARCHIVE_STATE_NEW, "archive_read_support_format_lha");
 
-       lha = (struct lha *)calloc(1, sizeof(*lha));
+       lha = calloc(1, sizeof(*lha));
        if (lha == NULL) {
                archive_set_error(&a->archive, ENOMEM,
                    "Can't allocate lha data");
index 6971228eefadb801fec012ed9a19e7bd7e7a746c..ba0e49de24080131997269904192695c53b85842 100644 (file)
@@ -273,7 +273,7 @@ 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 *)calloc(1, sizeof(*mtree));
+       mtree = calloc(1, sizeof(*mtree));
        if (mtree == NULL) {
                archive_set_error(&a->archive, ENOMEM,
                    "Can't allocate mtree data");
index cbc6ec984068d62ef1e5d4acde69e9225dbe287c..af2831b361e46c3958bc62d20d51d1cb4ab9e2be 100644 (file)
@@ -734,7 +734,7 @@ 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 *)calloc(1, sizeof(*rar));
+  rar = calloc(1, sizeof(*rar));
   if (rar == NULL)
   {
     archive_set_error(&a->archive, ENOMEM, "Can't allocate rar data");
@@ -2802,9 +2802,7 @@ make_table(struct archive_read *a, struct huffman_code *code)
   else
     code->tablesize = code->maxlength;
 
-  code->table =
-    (struct huffman_table_entry *)calloc(1, sizeof(*code->table)
-    * ((size_t)1 << code->tablesize));
+  code->table = calloc(1U << code->tablesize, sizeof(*code->table));
 
   return make_table_recurse(a, code, 0, code->table, 0, code->tablesize);
 }
index d23ef31844bed377dcc30d62073ef31ddfdd1e13..cafd064ad67869a3692657017f1133e65b29a84f 100644 (file)
@@ -535,8 +535,7 @@ static void write_filter_data(struct rar5* rar, uint32_t offset,
 
 /* Allocates a new filter descriptor and adds it to the filter array. */
 static struct filter_info* add_new_filter(struct rar5* rar) {
-       struct filter_info* f =
-               (struct filter_info*) calloc(1, sizeof(struct filter_info));
+       struct filter_info* f = calloc(1, sizeof(*f));
 
        if(!f) {
                return NULL;
@@ -1846,27 +1845,25 @@ static int process_head_file(struct archive_read* a, struct rar5* rar,
 
                if (file_attr & (ATTR_READONLY | ATTR_HIDDEN | ATTR_SYSTEM)) {
                        char *fflags_text, *ptr;
-                       /* allocate for "rdonly,hidden,system," */
-                       fflags_text = malloc(22 * sizeof(char));
+                       /* allocate for ",rdonly,hidden,system" */
+                       fflags_text = malloc(22 * sizeof(*fflags_text));
                        if (fflags_text != NULL) {
                                ptr = fflags_text;
                                if (file_attr & ATTR_READONLY) {
-                                       strcpy(ptr, "rdonly,");
+                                       strcpy(ptr, ",rdonly");
                                        ptr = ptr + 7;
                                }
                                if (file_attr & ATTR_HIDDEN) {
-                                       strcpy(ptr, "hidden,");
+                                       strcpy(ptr, ",hidden");
                                        ptr = ptr + 7;
                                }
                                if (file_attr & ATTR_SYSTEM) {
-                                       strcpy(ptr, "system,");
+                                       strcpy(ptr, ",system");
                                        ptr = ptr + 7;
                                }
                                if (ptr > fflags_text) {
-                                       /* Delete trailing comma */
-                                       *(ptr - 1) = '\0';
                                        archive_entry_copy_fflags_text(entry,
-                                           fflags_text);
+                                           fflags_text + 1);
                                }
                                free(fflags_text);
                        }
index efdbf276baf74942c418b2e8c47f8d0130639825..e935396dda6fce37aad07996a2f71590cd9defea 100644 (file)
@@ -61,7 +61,7 @@ archive_read_support_format_raw(struct archive *_a)
        archive_check_magic(_a, ARCHIVE_READ_MAGIC,
            ARCHIVE_STATE_NEW, "archive_read_support_format_raw");
 
-       info = (struct raw_info *)calloc(1, sizeof(*info));
+       info = calloc(1, sizeof(*info));
        if (info == NULL) {
                archive_set_error(&a->archive, ENOMEM,
                    "Can't allocate raw_info data");
index 739b8c6fcfe9edced94f9ae6a94048059582ab60..4f42db8f0efe64448b180e81640d71e1f3d34a0d 100644 (file)
@@ -256,7 +256,7 @@ archive_read_support_format_tar(struct archive *_a)
        archive_check_magic(_a, ARCHIVE_READ_MAGIC,
            ARCHIVE_STATE_NEW, "archive_read_support_format_tar");
 
-       tar = (struct tar *)calloc(1, sizeof(*tar));
+       tar = calloc(1, sizeof(*tar));
        if (tar == NULL) {
                archive_set_error(&a->archive, ENOMEM,
                    "Can't allocate tar data");
@@ -2908,7 +2908,7 @@ gnu_add_sparse_entry(struct archive_read *a, struct tar *tar,
 {
        struct sparse_block *p;
 
-       p = (struct sparse_block *)calloc(1, sizeof(*p));
+       p = calloc(1, sizeof(*p));
        if (p == NULL) {
                archive_set_error(&a->archive, ENOMEM, "Out of memory");
                return (ARCHIVE_FATAL);
@@ -3480,7 +3480,7 @@ base64_decode(const char *s, size_t len, size_t *out_len)
 
        /* Allocate enough space to hold the entire output. */
        /* Note that we may not use all of this... */
-       out = (char *)malloc(len - len / 4 + 1);
+       out = malloc(len - len / 4 + 1);
        if (out == NULL) {
                *out_len = 0;
                return (NULL);
@@ -3535,7 +3535,7 @@ url_decode(const char *in, size_t length)
        char *out, *d;
        const char *s;
 
-       out = (char *)malloc(length + 1);
+       out = malloc(length + 1);
        if (out == NULL)
                return (NULL);
        for (s = in, d = out; length > 0 && *s != '\0'; ) {
index 7c327e02f9cfc6997494fc3cf0133bb63d6ced7c..ffffab9638adcb7db52bc32a40038aaad9cb8e06 100644 (file)
@@ -450,7 +450,7 @@ archive_read_support_format_xar(struct archive *_a)
        archive_check_magic(_a, ARCHIVE_READ_MAGIC,
            ARCHIVE_STATE_NEW, "archive_read_support_format_xar");
 
-       xar = (struct xar *)calloc(1, sizeof(*xar));
+       xar = calloc(1, sizeof(*xar));
        if (xar == NULL) {
                archive_set_error(&a->archive, ENOMEM,
                    "Can't allocate xar data");
index 689346882ec78f576d3131f94898823ec1cffbf6..3e62533bf2d9c18b3a9be8bcd9de02f46bbb2313 100644 (file)
@@ -1751,8 +1751,7 @@ zipx_xz_init(struct archive_read *a, struct zip *zip)
        free(zip->uncompressed_buffer);
 
        zip->uncompressed_buffer_size = 256 * 1024;
-       zip->uncompressed_buffer =
-           (uint8_t*) malloc(zip->uncompressed_buffer_size);
+       zip->uncompressed_buffer = malloc(zip->uncompressed_buffer_size);
        if (zip->uncompressed_buffer == NULL) {
                archive_set_error(&a->archive, ENOMEM,
                    "No memory for xz decompression");
@@ -1862,8 +1861,7 @@ zipx_lzma_alone_init(struct archive_read *a, struct zip *zip)
 
        if(!zip->uncompressed_buffer) {
                zip->uncompressed_buffer_size = 256 * 1024;
-               zip->uncompressed_buffer =
-                       (uint8_t*) malloc(zip->uncompressed_buffer_size);
+               zip->uncompressed_buffer = malloc(zip->uncompressed_buffer_size);
 
                if (zip->uncompressed_buffer == NULL) {
                        archive_set_error(&a->archive, ENOMEM,
@@ -2167,8 +2165,7 @@ zipx_ppmd8_init(struct archive_read *a, struct zip *zip)
        free(zip->uncompressed_buffer);
 
        zip->uncompressed_buffer_size = 256 * 1024;
-       zip->uncompressed_buffer =
-           (uint8_t*) malloc(zip->uncompressed_buffer_size);
+       zip->uncompressed_buffer = malloc(zip->uncompressed_buffer_size);
 
        if(zip->uncompressed_buffer == NULL) {
                archive_set_error(&a->archive, ENOMEM,
@@ -2291,8 +2288,7 @@ zipx_bzip2_init(struct archive_read *a, struct zip *zip)
        free(zip->uncompressed_buffer);
 
        zip->uncompressed_buffer_size = 256 * 1024;
-       zip->uncompressed_buffer =
-           (uint8_t*) malloc(zip->uncompressed_buffer_size);
+       zip->uncompressed_buffer = malloc(zip->uncompressed_buffer_size);
        if (zip->uncompressed_buffer == NULL) {
                archive_set_error(&a->archive, ENOMEM,
                    "No memory for bzip2 decompression");
@@ -2434,8 +2430,7 @@ zipx_zstd_init(struct archive_read *a, struct zip *zip)
        free(zip->uncompressed_buffer);
 
        zip->uncompressed_buffer_size = ZSTD_DStreamOutSize();
-       zip->uncompressed_buffer =
-           (uint8_t*) malloc(zip->uncompressed_buffer_size);
+       zip->uncompressed_buffer = malloc(zip->uncompressed_buffer_size);
        if (zip->uncompressed_buffer == NULL) {
                archive_set_error(&a->archive, ENOMEM,
                        "No memory for Zstd decompression");
@@ -2574,7 +2569,7 @@ zip_read_data_deflate(struct archive_read *a, const void **buff,
        if (zip->uncompressed_buffer == NULL) {
                zip->uncompressed_buffer_size = 256 * 1024;
                zip->uncompressed_buffer
-                   = (unsigned char *)malloc(zip->uncompressed_buffer_size);
+                   = malloc(zip->uncompressed_buffer_size);
                if (zip->uncompressed_buffer == NULL) {
                        archive_set_error(&a->archive, ENOMEM,
                            "No memory for ZIP decompression");
@@ -3600,7 +3595,7 @@ archive_read_support_format_zip_streamable(struct archive *_a)
        archive_check_magic(_a, ARCHIVE_READ_MAGIC,
            ARCHIVE_STATE_NEW, "archive_read_support_format_zip");
 
-       zip = (struct zip *)calloc(1, sizeof(*zip));
+       zip = calloc(1, sizeof(*zip));
        if (zip == NULL) {
                archive_set_error(&a->archive, ENOMEM,
                    "Can't allocate zip data");
@@ -4392,7 +4387,7 @@ archive_read_support_format_zip_seekable(struct archive *_a)
        archive_check_magic(_a, ARCHIVE_READ_MAGIC,
            ARCHIVE_STATE_NEW, "archive_read_support_format_zip_seekable");
 
-       zip = (struct zip *)calloc(1, sizeof(*zip));
+       zip = calloc(1, sizeof(*zip));
        if (zip == NULL) {
                archive_set_error(&a->archive, ENOMEM,
                    "Can't allocate zip data");
index 41bfe7af1d96fb489260f6fa160393f10996c39e..abf7ad669351783ce1ca1fb5f5fcd2baf63abe12 100644 (file)
@@ -313,7 +313,7 @@ archive_string_ensure(struct archive_string *as, size_t s)
        if (new_length < s)
                new_length = s;
        /* Now we can reallocate the buffer. */
-       p = (char *)realloc(as->s, new_length);
+       p = realloc(as->s, new_length);
        if (p == NULL) {
                /* On failure, wipe the string and return NULL. */
                archive_string_free(as);
index 46d03f926def82f9bbbb71d03c06d3c5a324e7e2..3a8caad5262b5c33812baaeaf34fc7a70e36fc22 100644 (file)
@@ -651,8 +651,7 @@ archive_utility_string_sort_helper(char **strings, unsigned int n)
                if (strcmp(strings[i], pivot) < 0)
                {
                        lesser_count++;
-                       tmp = (char **)realloc(lesser,
-                               lesser_count * sizeof(char *));
+                       tmp = realloc(lesser, lesser_count * sizeof(*tmp));
                        if (!tmp) {
                                free(greater);
                                free(lesser);
@@ -664,8 +663,7 @@ archive_utility_string_sort_helper(char **strings, unsigned int n)
                else
                {
                        greater_count++;
-                       tmp = (char **)realloc(greater,
-                               greater_count * sizeof(char *));
+                       tmp = realloc(greater, greater_count * sizeof(*tmp));
                        if (!tmp) {
                                free(greater);
                                free(lesser);
index e1a4f34bfc3cd3080dde723a79e6890a7f724d4f..303c686881a9080969f96591714ef4e94406e2c7 100644 (file)
@@ -98,7 +98,7 @@ archive_write_new(void)
        struct archive_write *a;
        unsigned char *nulls;
 
-       a = (struct archive_write *)calloc(1, sizeof(*a));
+       a = calloc(1, sizeof(*a));
        if (a == NULL)
                return (NULL);
        a->archive.magic = ARCHIVE_WRITE_MAGIC;
@@ -114,7 +114,7 @@ archive_write_new(void)
 
        /* Initialize a block of nulls for padding purposes. */
        a->null_length = 1024;
-       nulls = (unsigned char *)calloc(a->null_length, sizeof(unsigned char));
+       nulls = calloc(a->null_length, sizeof(unsigned char));
        if (nulls == NULL) {
                free(a);
                return (NULL);
@@ -367,8 +367,8 @@ archive_write_client_open(struct archive_write_filter *f)
            archive_write_get_bytes_in_last_block(f->archive);
        buffer_size = f->bytes_per_block;
 
-       state = (struct archive_none *)calloc(1, sizeof(*state));
-       buffer = (char *)malloc(buffer_size);
+       state = calloc(1, sizeof(*state));
+       buffer = malloc(buffer_size);
        if (state == NULL || buffer == NULL) {
                free(state);
                free(buffer);
index 3aca6d81d22156e2f43ead66eca55e85de7bd86d..2c361bfb974eff0236eefd2011966b55603655c6 100644 (file)
@@ -85,7 +85,7 @@ archive_write_add_filter_b64encode(struct archive *_a)
        archive_check_magic(&a->archive, ARCHIVE_WRITE_MAGIC,
            ARCHIVE_STATE_NEW, "archive_write_add_filter_b64encode");
 
-       state = (struct private_b64encode *)calloc(1, sizeof(*state));
+       state = calloc(1, sizeof(*state));
        if (state == NULL) {
                archive_set_error(f->archive, ENOMEM,
                    "Can't allocate data for b64encode filter");
index bc0ef2607127153adbb4531dc910c1b833513d8c..0726f08936ec1d9180f2a5a604488dafb8bd7629 100644 (file)
@@ -177,8 +177,7 @@ archive_compressor_bzip2_open(struct archive_write_filter *f)
                                bs -= bs % bpb;
                }
                data->compressed_buffer_size = bs;
-               data->compressed
-                   = (char *)malloc(data->compressed_buffer_size);
+               data->compressed = malloc(data->compressed_buffer_size);
                if (data->compressed == NULL) {
                        archive_set_error(f->archive, ENOMEM,
                            "Can't allocate data for compression buffer");
index e547e8872860b1a79b17743e8afeb68c3be95d56..a54a85754293817df770eb69034fb638ad4af5f6 100644 (file)
@@ -150,7 +150,7 @@ archive_compressor_compress_open(struct archive_write_filter *f)
        f->code = ARCHIVE_FILTER_COMPRESS;
        f->name = "compress";
 
-       state = (struct private_data *)calloc(1, sizeof(*state));
+       state = calloc(1, sizeof(*state));
        if (state == NULL) {
                archive_set_error(f->archive, ENOMEM,
                    "Can't allocate data for compression");
index a7fabbfa6bd5c358590bec70dc14149b605713fb..71d7891261a5db71988ad985990fa62c0d5cb6e3 100644 (file)
@@ -194,8 +194,7 @@ archive_compressor_gzip_open(struct archive_write_filter *f)
                                bs -= bs % bpb;
                }
                data->compressed_buffer_size = bs;
-               data->compressed
-                   = (unsigned char *)malloc(data->compressed_buffer_size);
+               data->compressed = malloc(data->compressed_buffer_size);
                if (data->compressed == NULL) {
                        archive_set_error(f->archive, ENOMEM,
                            "Can't allocate data for compression buffer");
index 42dec8def1f1ad0bb7a5fa94d9b5744b0d9f0003..50bfeb6eaa60c251a30e1d5b66992e953cfb8b3a 100644 (file)
@@ -74,7 +74,7 @@ archive_write_add_filter_uuencode(struct archive *_a)
        archive_check_magic(&a->archive, ARCHIVE_WRITE_MAGIC,
            ARCHIVE_STATE_NEW, "archive_write_add_filter_uu");
 
-       state = (struct private_uuencode *)calloc(1, sizeof(*state));
+       state = calloc(1, sizeof(*state));
        if (state == NULL) {
                archive_set_error(f->archive, ENOMEM,
                    "Can't allocate data for uuencode filter");
index e09d5e91739377166b8fb6c2d72dd538d8e69e56..098f0c95570b68cd67fd94c685d431e4e119abde 100644 (file)
@@ -319,8 +319,7 @@ archive_compressor_xz_open(struct archive_write_filter *f)
                                bs -= bs % bpb;
                }
                data->compressed_buffer_size = bs;
-               data->compressed
-                   = (unsigned char *)malloc(data->compressed_buffer_size);
+               data->compressed = malloc(data->compressed_buffer_size);
                if (data->compressed == NULL) {
                        archive_set_error(f->archive, ENOMEM,
                            "Can't allocate data for compression buffer");
index 7ea3d18c9b766c2240f97bc8074b91b3e8c11060..c0a6e5a37a6626db3136f12c00aa41f65ad69c3e 100644 (file)
@@ -372,8 +372,7 @@ archive_compressor_zstd_open(struct archive_write_filter *f)
                }
                data->out.size = bs;
                data->out.pos = 0;
-               data->out.dst
-                   = (unsigned char *)malloc(data->out.size);
+               data->out.dst = malloc(data->out.size);
                if (data->out.dst == NULL) {
                        archive_set_error(f->archive, ENOMEM,
                            "Can't allocate data for compression buffer");
index 098a8fe4113feb5432b70c7e8e1fc98af4118985..d9619fe2d122366df02391d3c14267f1f113fb9d 100644 (file)
@@ -1991,7 +1991,7 @@ archive_write_disk_new(void)
 {
        struct archive_write_disk *a;
 
-       a = (struct archive_write_disk *)calloc(1, sizeof(*a));
+       a = calloc(1, sizeof(*a));
        if (a == NULL)
                return (NULL);
        a->archive.magic = ARCHIVE_WRITE_DISK_MAGIC;
@@ -2758,7 +2758,7 @@ new_fixup(struct archive_write_disk *a, const char *pathname)
 {
        struct fixup_entry *fe;
 
-       fe = (struct fixup_entry *)calloc(1, sizeof(struct fixup_entry));
+       fe = calloc(1, sizeof(struct fixup_entry));
        if (fe == NULL) {
                archive_set_error(&a->archive, ENOMEM,
                    "Can't allocate memory for a fixup");
index f0de73131faafd542b8ccd0691bd6817535c96c2..086f796938c7d8c1620f7359bb34f09d5e8f8430 100644 (file)
@@ -1389,7 +1389,7 @@ archive_write_disk_new(void)
 {
        struct archive_write_disk *a;
 
-       a = (struct archive_write_disk *)calloc(1, sizeof(*a));
+       a = calloc(1, sizeof(*a));
        if (a == NULL)
                return (NULL);
        a->archive.magic = ARCHIVE_WRITE_DISK_MAGIC;
@@ -2079,7 +2079,7 @@ new_fixup(struct archive_write_disk *a, const wchar_t *pathname)
 {
        struct fixup_entry *fe;
 
-       fe = (struct fixup_entry *)calloc(1, sizeof(struct fixup_entry));
+       fe = calloc(1, sizeof(struct fixup_entry));
        if (fe == NULL)
                return (NULL);
        fe->next = a->fixup_list;
index a58ae047967b19459f050f63fd25b91b979baa78..8a3f68d0699dc060c9801eb7ceec64cfbb1fbe2a 100644 (file)
@@ -62,7 +62,7 @@ archive_write_open_fd(struct archive *a, int fd)
 {
        struct write_fd_data *mine;
 
-       mine = (struct write_fd_data *)malloc(sizeof(*mine));
+       mine = malloc(sizeof(*mine));
        if (mine == NULL) {
                archive_set_error(a, ENOMEM, "No memory");
                return (ARCHIVE_FATAL);
index d787da3af388e28d3fd92a2950e118c7fac17c73..4c6ebfb2269dfe9cd98c2504b91c442909b751a6 100644 (file)
@@ -59,7 +59,7 @@ archive_write_open_FILE(struct archive *a, FILE *f)
 {
        struct write_FILE_data *mine;
 
-       mine = (struct write_FILE_data *)malloc(sizeof(*mine));
+       mine = malloc(sizeof(*mine));
        if (mine == NULL) {
                archive_set_error(a, ENOMEM, "No memory");
                return (ARCHIVE_FATAL);
index 7dc73d55f43e6779d75aea9d14445f24fcc7d5d2..6842b98d2f07c15a6b8c09bf062ccb9a830f8542 100644 (file)
@@ -98,7 +98,7 @@ open_filename(struct archive *a, int mbs_fn, const void *filename)
        struct write_file_data *mine;
        int r;
 
-       mine = (struct write_file_data *)calloc(1, sizeof(*mine));
+       mine = calloc(1, sizeof(*mine));
        if (mine == NULL) {
                archive_set_error(a, ENOMEM, "No memory");
                return (ARCHIVE_FATAL);
index 609cc47d964a36c6eb23fbc69bb23485bb0e508e..e31650447279f8bb8cda8f265492e347499ab9b8 100644 (file)
@@ -52,7 +52,7 @@ archive_write_open_memory(struct archive *a, void *buff, size_t buffSize, size_t
 {
        struct write_memory_data *mine;
 
-       mine = (struct write_memory_data *)calloc(1, sizeof(*mine));
+       mine = calloc(1, sizeof(*mine));
        if (mine == NULL) {
                archive_set_error(a, ENOMEM, "No memory");
                return (ARCHIVE_FATAL);
index 38689d89be0e9582a78938cf1703900262a9b49a..e5e9c806b6398eb9f69986e9cead415ce2c78364 100644 (file)
@@ -126,7 +126,7 @@ archive_write_set_format_ar(struct archive_write *a)
        if (a->format_free != NULL)
                (a->format_free)(a);
 
-       ar = (struct ar_w *)calloc(1, sizeof(*ar));
+       ar = calloc(1, sizeof(*ar));
        if (ar == NULL) {
                archive_set_error(&a->archive, ENOMEM, "Can't allocate ar data");
                return (ARCHIVE_FATAL);
@@ -246,7 +246,7 @@ archive_write_ar_header(struct archive_write *a, struct archive_entry *entry)
                                return (ARCHIVE_WARN);
                        }
 
-                       se = (char *)malloc(strlen(filename) + 3);
+                       se = malloc(strlen(filename) + 3);
                        if (se == NULL) {
                                archive_set_error(&a->archive, ENOMEM,
                                    "Can't allocate filename buffer");
@@ -379,7 +379,7 @@ archive_write_ar_data(struct archive_write *a, const void *buff, size_t s)
                        return (ARCHIVE_WARN);
                }
 
-               ar->strtab = (char *)malloc(s + 1);
+               ar->strtab = malloc(s + 1);
                if (ar->strtab == NULL) {
                        archive_set_error(&a->archive, ENOMEM,
                            "Can't allocate strtab buffer");
index a22d06ea3838e0f47525a67eb9f487ae7f243baa..aefb2ca6f51487c3727858927f8f88872247bd35 100644 (file)
@@ -185,7 +185,7 @@ archive_write_set_format_cpio_binary(struct archive *_a, int format)
        if (a->format_free != NULL)
                (a->format_free)(a);
 
-       cpio = (struct cpio *)calloc(1, sizeof(*cpio));
+       cpio = calloc(1, sizeof(*cpio));
        if (cpio == NULL) {
                archive_set_error(&a->archive, ENOMEM, "Can't allocate cpio data");
                return (ARCHIVE_FATAL);
index 006736a1fa22452de307615b9376c7f3fe02138d..254d5a9901c3680f88ffe0e7c3cad1105e4bde54 100644 (file)
@@ -116,7 +116,7 @@ archive_write_set_format_cpio_newc(struct archive *_a)
        if (a->format_free != NULL)
                (a->format_free)(a);
 
-       cpio = (struct cpio *)calloc(1, sizeof(*cpio));
+       cpio = calloc(1, sizeof(*cpio));
        if (cpio == NULL) {
                archive_set_error(&a->archive, ENOMEM, "Can't allocate cpio data");
                return (ARCHIVE_FATAL);
index 6dce78b45452e650740b1f707aceaf661e03eae8..c72c6b2796bfb7f2ca56354e69d2e0f94d73d51d 100644 (file)
@@ -110,7 +110,7 @@ archive_write_set_format_cpio_odc(struct archive *_a)
        if (a->format_free != NULL)
                (a->format_free)(a);
 
-       cpio = (struct cpio *)calloc(1, sizeof(*cpio));
+       cpio = calloc(1, sizeof(*cpio));
        if (cpio == NULL) {
                archive_set_error(&a->archive, ENOMEM, "Can't allocate cpio data");
                return (ARCHIVE_FATAL);
index 8979078ee4bb51cf5dff27c35d7a8360d03fb4e2..04b190de4402ece5d60cf6c37190d5307edcdf4b 100644 (file)
@@ -174,7 +174,7 @@ archive_write_set_format_gnutar(struct archive *_a)
        struct archive_write *a = (struct archive_write *)_a;
        struct gnutar *gnutar;
 
-       gnutar = (struct gnutar *)calloc(1, sizeof(*gnutar));
+       gnutar = calloc(1, sizeof(*gnutar));
        if (gnutar == NULL) {
                archive_set_error(&a->archive, ENOMEM,
                    "Can't allocate gnutar data");
index 4aace4682587089bce3e5f0613dec4a1b1dbc2ec..6e35f705e136d35633238ce99f0985b5137019d6 100644 (file)
@@ -138,7 +138,7 @@ archive_write_set_format_pax(struct archive *_a)
        if (a->format_free != NULL)
                (a->format_free)(a);
 
-       pax = (struct pax *)calloc(1, sizeof(*pax));
+       pax = calloc(1, sizeof(*pax));
        if (pax == NULL) {
                archive_set_error(&a->archive, ENOMEM,
                    "Can't allocate pax data");
@@ -1944,7 +1944,7 @@ url_encode(const char *in)
                }
        }
 
-       out = (char *)malloc(out_len + 1);
+       out = malloc(out_len + 1);
        if (out == NULL)
                return (NULL);
 
@@ -1982,7 +1982,7 @@ base64_encode(const char *s, size_t len)
        char *d, *out;
 
        /* 3 bytes becomes 4 chars, but round up and allow for trailing NUL */
-       out = (char *)malloc((len * 4 + 2) / 3 + 1);
+       out = malloc((len * 4 + 2) / 3 + 1);
        if (out == NULL)
                return (NULL);
        d = out;
@@ -2037,7 +2037,7 @@ _sparse_list_add_block(struct pax *pax, int64_t offset, int64_t length,
 {
        struct sparse_block *sb;
 
-       sb = (struct sparse_block *)malloc(sizeof(*sb));
+       sb = malloc(sizeof(*sb));
        if (sb == NULL)
                return (ARCHIVE_FATAL);
        sb->next = NULL;
index feff936977361242c9d34810731606bf165e385f..ff3e9ae0ebdbddb83a40a1bf209c1104761c0788 100644 (file)
@@ -58,7 +58,7 @@ archive_write_set_format_raw(struct archive *_a)
        if (a->format_free != NULL)
                (a->format_free)(a);
 
-       raw = (struct raw *)calloc(1, sizeof(*raw));
+       raw = calloc(1, sizeof(*raw));
        if (raw == NULL) {
                archive_set_error(&a->archive, ENOMEM, "Can't allocate raw data");
                return (ARCHIVE_FATAL);
index da2bc0ca3edb3d11806bcda9b561a57d5ec6cee2..be9f78ce96cdf0ac23a75b5f9d0eff5eb49cc5fb 100644 (file)
@@ -113,7 +113,7 @@ archive_write_set_format_shar(struct archive *_a)
        if (a->format_free != NULL)
                (a->format_free)(a);
 
-       shar = (struct shar *)calloc(1, sizeof(*shar));
+       shar = calloc(1, sizeof(*shar));
        if (shar == NULL) {
                archive_set_error(&a->archive, ENOMEM, "Can't allocate shar data");
                return (ARCHIVE_FATAL);
index 9dc6e71f189f606a377be1c65144a5d2560c920f..09b71fe6672a0418fd4887510a69f3b96a3de686 100644 (file)
@@ -183,7 +183,7 @@ archive_write_set_format_ustar(struct archive *_a)
                return (ARCHIVE_FATAL);
        }
 
-       ustar = (struct ustar *)calloc(1, sizeof(*ustar));
+       ustar = calloc(1, sizeof(*ustar));
        if (ustar == NULL) {
                archive_set_error(&a->archive, ENOMEM,
                    "Can't allocate ustar data");
index ffb420f08ba115deac84c66a862532bc8a9776b3..2598fc076c0ca1ee6e466977630c398f80d5ceef 100644 (file)
@@ -160,7 +160,7 @@ archive_write_set_format_v7tar(struct archive *_a)
                return (ARCHIVE_FATAL);
        }
 
-       v7tar = (struct v7tar *)calloc(1, sizeof(*v7tar));
+       v7tar = calloc(1, sizeof(*v7tar));
        if (v7tar == NULL) {
                archive_set_error(&a->archive, ENOMEM,
                    "Can't allocate v7tar data");
index ad3e90759176ef9686b55442d8cdc90fab97f99b..a9f2877305e83b0a60676f6a905e6e55ca9655f1 100644 (file)
@@ -456,7 +456,7 @@ archive_write_set_format_zip(struct archive *_a)
        if (a->format_free != NULL)
                (a->format_free)(a);
 
-       zip = (struct zip *) calloc(1, sizeof(*zip));
+       zip = calloc(1, sizeof(*zip));
        if (zip == NULL) {
                archive_set_error(&a->archive, ENOMEM,
                    "Can't allocate zip data");
index f5adb5b7b567e97d5bfe4b2268b49097e93b6d6b..f9f75d96fa6be26e2d81b7abc902a3c0a2278d78 100644 (file)
@@ -184,7 +184,7 @@ file_open(struct archive *a, void *data)
     mydata->fd = open(mydata->filename, O_RDONLY | O_BINARY);
     if (mydata->fd >= 0)
     {
-      if ((mydata->buffer = (void*)calloc(BLOCK_SIZE, 1)) == NULL)
+      if ((mydata->buffer = calloc(BLOCK_SIZE, 1)) == NULL)
         return (ARCHIVE_FAILED);
     }
   }
@@ -280,28 +280,21 @@ test_customized_multiple_data_objects(void)
 
   for (i = 0; filename != NULL;)
   {
-    assert((mydata = (struct mydata *)calloc(1, sizeof(*mydata))) != NULL);
+    assert((mydata = calloc(1, sizeof(*mydata))) != NULL);
     if (mydata == NULL) {
       assertEqualInt(ARCHIVE_OK, archive_read_free(a));
       return;
     }
-    assert((mydata->filename =
-      (char *)calloc(strlen(filename) + 1, sizeof(char))) != NULL);
-    if (mydata->filename == NULL) {
-      free(mydata);
-      assertEqualInt(ARCHIVE_OK, archive_read_free(a));
-      return;
-    }
-    strcpy(mydata->filename, filename);
+    assert((mydata->filename = strdup(filename)) != NULL);
     mydata->fd = -1;
     filename = reffiles[++i];
     assertA(0 == archive_read_append_callback_data(a, mydata));
   }
-       assertA(0 == archive_read_set_open_callback(a, file_open));
-       assertA(0 == archive_read_set_read_callback(a, file_read));
-       assertA(0 == archive_read_set_skip_callback(a, file_skip));
-       assertA(0 == archive_read_set_close_callback(a, file_close));
-       assertA(0 == archive_read_set_switch_callback(a, file_switch));
+  assertA(0 == archive_read_set_open_callback(a, file_open));
+  assertA(0 == archive_read_set_read_callback(a, file_read));
+  assertA(0 == archive_read_set_skip_callback(a, file_skip));
+  assertA(0 == archive_read_set_close_callback(a, file_close));
+  assertA(0 == archive_read_set_switch_callback(a, file_switch));
   assertA(0 == archive_read_set_seek_callback(a, file_seek));
   assertA(0 == archive_read_open1(a));
 
index f8f1e337bf7327bd1e07030b4c253276b42a4dd6..30f7a800eae8e4526acf2778ae8af79b576d5f74 100644 (file)
@@ -405,7 +405,7 @@ DEFINE_TEST(test_archive_string_sort)
 
   srand((unsigned int)time(NULL));
   size = sizeof(strings) / sizeof(char *);
-  assert((test_strings = (char **)calloc(size, sizeof(char *))) != NULL);
+  assert((test_strings = calloc(size, sizeof(char *))) != NULL);
   for (i = 0; i < (size - 1); i++)
     assert((test_strings[i] = strdup(strings[i])) != NULL);
 
index c80e161c3b58d38b17b261a7da7dbabd51ab1938..9d7e58d6f635c42276e484d608f11f9ca372ce24 100644 (file)
@@ -36,7 +36,7 @@ test_filter_by_name(const char *filter_name, int filter_code,
        char *buff;
        int r;
 
-       assert((buff = calloc(buffsize, sizeof(char))) != NULL);
+       assert((buff = calloc(buffsize, sizeof(*buff))) != NULL);
        if (buff == NULL)
                return;
 
index 41cbd7dab96fe76089e0e718b1feed9621f9e6b0..5c306e58522e5c689c1c76f417584ae694c5640e 100644 (file)
@@ -620,7 +620,7 @@ has the corresponding timestamps unset.
   archive_write_set_format_xar(a);
   archive_write_add_filter_none(a);
   size_t used, buffsize = 1500;
-  char *buff = (char*) malloc(buffsize);
+  char *buff = malloc(buffsize);
   archive_write_open_memory(a, buff, buffsize, &used);
 
   struct archive_entry *ae = archive_entry_new();
@@ -827,7 +827,7 @@ static void verifyB(unsigned char *d, size_t s) {
        assertA(0 == archive_read_next_header(a, &entry));
        buf_size = (size_t) archive_entry_size(entry);
        assertA(buf_size == 12);
-       buf = (unsigned char*) malloc(buf_size);
+       buf = malloc(buf_size);
        assertA(NULL != buf);
        assertA(buf_size == (size_t) archive_read_data(a, buf, buf_size));
        free(buf);
@@ -836,7 +836,7 @@ static void verifyB(unsigned char *d, size_t s) {
        assertA(0 == archive_read_next_header(a, &entry));
        buf_size = (size_t) archive_entry_size(entry);
        assertA(buf_size == 12);
-       buf = (unsigned char*) malloc(buf_size);
+       buf = malloc(buf_size);
        assertA(NULL != buf);
        assertA(buf_size == (size_t) archive_read_data(a, buf, buf_size));
        free(buf);
index 95945638b074c82a221650126ae2bd7a15ea71d7..b32e4bb942115be8a7f34e0c9b7a80151ed18c97 100644 (file)
@@ -49,7 +49,7 @@ DEFINE_TEST(test_read_format_zip_nested)
 
        /* Save contents of inner Zip. */
        innerLength = (size_t)archive_entry_size(ae);
-       inner = calloc(innerLength, sizeof(char));
+       inner = calloc(innerLength, sizeof(*inner));
        assertEqualInt(innerLength, archive_read_data(a, inner, innerLength));
 
        assertEqualIntA(a, ARCHIVE_OK, archive_read_next_header(a, &ae));
index 9c5348d935d2adb4b9f0d6b74475508d091a2b5c..fc8ddf51b73bf63066c8e4c843f86c89ee36e528 100644 (file)
@@ -43,12 +43,12 @@ test_truncation(const char *compression,
        int i, r, use_prog;
 
        buffsize = 2000000;
-       assert(NULL != (buff = (char *)malloc(buffsize)));
+       assert(NULL != (buff = malloc(buffsize)));
        if (buff == NULL)
                return;
 
        datasize = 10000;
-       assert(NULL != (data = (char *)malloc(datasize)));
+       assert(NULL != (data = malloc(datasize)));
        if (data == NULL) {
                free(buff);
                return;
index 7ff3fee17717ecc569240a99bf3c832bfa40b516..c1f379162ad770a8b68189179b8c62bf4652f2bb 100644 (file)
@@ -99,7 +99,7 @@ memory_write(struct archive *a, void *_private, const void *buff, size_t size)
        } else {
                /* Yes, we're assuming the very first write is metadata. */
                /* It's header or metadata, copy and save it. */
-               block = (struct memblock *)malloc(sizeof(*block));
+               block = malloc(sizeof(*block));
                memset(block, 0, sizeof(*block));
                block->size = size;
                block->buff = malloc(size);
index e33ff8a9817c7a55f324169be4f174eed2f09e0c..d7c4763b1cdcce1ffebbca30bb953d7b02ec2f1c 100644 (file)
@@ -41,10 +41,10 @@ DEFINE_TEST(test_write_filter_b64encode)
        int i;
 
        buffsize = 2000000;
-       assert(NULL != (buff = (char *)malloc(buffsize)));
+       assert(NULL != (buff = malloc(buffsize)));
 
        datasize = 10000;
-       assert(NULL != (data = (char *)malloc(datasize)));
+       assert(NULL != (data = malloc(datasize)));
        memset(data, 0, datasize);
 
        /*
index f48bcc2132312e6bde9d6625f3f56572f86ce8dd..20ca0d9a7b224d71c4eeea572e2184fb6f815782 100644 (file)
@@ -43,12 +43,12 @@ DEFINE_TEST(test_write_filter_bzip2)
        int i, r, use_prog;
 
        buffsize = 2000000;
-       assert(NULL != (buff = (char *)malloc(buffsize)));
+       assert(NULL != (buff = malloc(buffsize)));
        if (buff == NULL)
                return;
 
        datasize = 10000;
-       assert(NULL != (data = (char *)malloc(datasize)));
+       assert(NULL != (data = malloc(datasize)));
        if (data == NULL) {
                free(buff);
                return;
index f7b9565b7db2949e332524f7e56ba2eb49b9877c..6a0c022c48e1a38eac416d2cae2c0dd78c1ebe44 100644 (file)
@@ -43,10 +43,10 @@ DEFINE_TEST(test_write_filter_compress)
        int i;
 
        buffsize = 1000000;
-       assert(NULL != (buff = (char *)malloc(buffsize)));
+       assert(NULL != (buff = malloc(buffsize)));
 
        datasize = 10000;
-       assert(NULL != (data = (char *)malloc(datasize)));
+       assert(NULL != (data = malloc(datasize)));
        memset(data, 0, datasize);
 
        assert((a = archive_write_new()) != NULL);
index ae81a4fc59d6fb538fc70b4519f239d39092bf68..14b14ecdd10577eb403cea3fb63e2a717865d491 100644 (file)
@@ -44,12 +44,12 @@ DEFINE_TEST(test_write_filter_gzip)
        int i, r, use_prog = 0;
 
        buffsize = 2000000;
-       assert(NULL != (buff = (char *)malloc(buffsize)));
+       assert(NULL != (buff = malloc(buffsize)));
        if (buff == NULL)
                return;
 
        datasize = 10000;
-       assert(NULL != (data = (char *)malloc(datasize)));
+       assert(NULL != (data = malloc(datasize)));
        if (data == NULL) {
                free(buff);
                return;
index ee29f034231c16acaae2b3ee12f13044b1acd2e7..a148f818dceca16bce932c323e6445df8df007d5 100644 (file)
@@ -37,12 +37,12 @@ DEFINE_TEST(test_write_filter_gzip_timestamp)
        int r, use_prog = 0;
 
        buffsize = 10000;
-       assert(NULL != (buff = (char *)malloc(buffsize)));
+       assert(NULL != (buff = malloc(buffsize)));
        if (buff == NULL)
                return;
 
        datasize = 10000;
-       assert(NULL != (data = (char *)malloc(datasize)));
+       assert(NULL != (data = malloc(datasize)));
        if (data == NULL) {
                free(buff);
                return;
index 2efc2ec284a4b4936adb1cb5803f49fa752d4a44..8da7ae39af5dea3adc3b2d0aafc14046e7a3ae3a 100644 (file)
@@ -46,10 +46,10 @@ DEFINE_TEST(test_write_filter_lrzip)
        }
 
        buffsize = 2000000;
-       assert(NULL != (buff = (char *)malloc(buffsize)));
+       assert(NULL != (buff = malloc(buffsize)));
 
        datasize = 10000;
-       assert(NULL != (data = (char *)malloc(datasize)));
+       assert(NULL != (data = malloc(datasize)));
        memset(data, 0, datasize);
 
        /*
index 97a80321dedea4b2f6333e937efe36c90b512dfc..74a910b53530a80e5ada7dfba900abc6c75f99b7 100644 (file)
@@ -58,10 +58,10 @@ DEFINE_TEST(test_write_filter_lz4)
        assertEqualInt(ARCHIVE_OK, archive_write_free(a));
 
        buffsize = 2000000;
-       assert(NULL != (buff = (char *)malloc(buffsize)));
+       assert(NULL != (buff = malloc(buffsize)));
 
        datasize = 10000;
-       assert(NULL != (data = (char *)calloc(datasize, 1)));
+       assert(NULL != (data = calloc(datasize, 1)));
        filecount = 10;
 
        /*
@@ -302,10 +302,10 @@ test_options(const char *options)
        assertEqualInt(ARCHIVE_OK, archive_write_free(a));
 
        buffsize = 2000000;
-       assert(NULL != (buff = (char *)malloc(buffsize)));
+       assert(NULL != (buff = malloc(buffsize)));
 
        datasize = 10000;
-       assert(NULL != (data = (char *)calloc(datasize, 1)));
+       assert(NULL != (data = calloc(datasize, 1)));
        filecount = 10;
 
        /*
index 8d6544668980d7b82a51c24442276ea43f613e8b..631fd96bd5ceaea0319ada0089acbaf555af1a64 100644 (file)
@@ -43,12 +43,12 @@ DEFINE_TEST(test_write_filter_lzip)
        int i, r;
 
        buffsize = 2000000;
-       assert(NULL != (buff = (char *)malloc(buffsize)));
+       assert(NULL != (buff = malloc(buffsize)));
        if (buff == NULL)
                return;
 
        datasize = 10000;
-       assert(NULL != (data = (char *)malloc(datasize)));
+       assert(NULL != (data = malloc(datasize)));
        if (data == NULL) {
                free(buff);
                return;
index d7c0c5b21b6b9f5295f7d730109e63902260101c..9bb2d8eb794350baf8250ed5f6b161a5a38d670b 100644 (file)
@@ -42,12 +42,12 @@ DEFINE_TEST(test_write_filter_lzma)
        int i, r;
 
        buffsize = 2000000;
-       assert(NULL != (buff = (char *)malloc(buffsize)));
+       assert(NULL != (buff = malloc(buffsize)));
        if (buff == NULL)
                return;
 
        datasize = 10000;
-       assert(NULL != (data = (char *)malloc(datasize)));
+       assert(NULL != (data = malloc(datasize)));
        if (data == NULL) {
                free(buff);
                return;
index 87843f49bd3bfcd592f5a71cfce2f1fdfe25cb88..8b74d224dcedba1be5972723d9e4f9b3e317412b 100644 (file)
@@ -52,10 +52,10 @@ DEFINE_TEST(test_write_filter_lzop)
        }
 
        buffsize = 2000000;
-       assert(NULL != (buff = (char *)malloc(buffsize)));
+       assert(NULL != (buff = malloc(buffsize)));
 
        datasize = 10000;
-       assert(NULL != (data = (char *)calloc(datasize, 1)));
+       assert(NULL != (data = calloc(datasize, 1)));
        filecount = 10;
 
        /*
index 7eda278b35cd443a062a4cd7e5741c7094952bc6..fbd0520880fe02e3ea7a1a3f9ac57353515503d4 100644 (file)
@@ -41,10 +41,10 @@ DEFINE_TEST(test_write_filter_uuencode)
        int i;
 
        buffsize = 2000000;
-       assert(NULL != (buff = (char *)malloc(buffsize)));
+       assert(NULL != (buff = malloc(buffsize)));
 
        datasize = 10000;
-       assert(NULL != (data = (char *)malloc(datasize)));
+       assert(NULL != (data = malloc(datasize)));
        memset(data, 0, datasize);
 
        /*
index db4e5dafa2743797304b473f118a19e469dd8a48..6baa0473b8e2f439ca1bcbfb4dcd230ae6499274 100644 (file)
@@ -43,12 +43,12 @@ DEFINE_TEST(test_write_filter_xz)
        int i, r;
 
        buffsize = 2000000;
-       assert(NULL != (buff = (char *)malloc(buffsize)));
+       assert(NULL != (buff = malloc(buffsize)));
        if (buff == NULL)
                return;
 
        datasize = 10000;
-       assert(NULL != (data = (char *)malloc(datasize)));
+       assert(NULL != (data = malloc(datasize)));
        if (data == NULL) {
                free(buff);
                return;
index 07fbaa8ea633ece9d76a30011002382b4f372ebf..41451ca86251e95b76c06b71bc8d4972cc4e414b 100644 (file)
@@ -37,12 +37,12 @@ DEFINE_TEST(test_write_filter_zstd)
        int i, r;
 
        buffsize = 2000000;
-       assert(NULL != (buff = (char *)malloc(buffsize)));
+       assert(NULL != (buff = malloc(buffsize)));
        if (buff == NULL)
                return;
 
        datasize = 10000;
-       assert(NULL != (data = (char *)malloc(datasize)));
+       assert(NULL != (data = malloc(datasize)));
        if (data == NULL) {
                free(buff);
                return;
index 713883bdc8cbb25cd425d58783c4022b7487544a..ca617c3a94d82c82f1173ea7dad1c4c64232483b 100644 (file)
@@ -321,7 +321,7 @@ DEFINE_TEST(test_write_format_iso9660_filename)
         */
        fcnt = create_iso_image(buff, buffsize, &used, NULL);
 
-       fns.names = (char **)malloc(sizeof(char *) * fcnt);
+       fns.names = malloc(sizeof(char *) * fcnt);
        assert(fns.names != NULL);
        if (fns.names == NULL) {
                free(buff);
index 90bd16aaa58105a3f13db6271e72441da3e6d0a2..d08dae46d8071c898389196a206168270bc80843 100644 (file)
@@ -96,7 +96,7 @@ memory_write(struct archive *a, void *_private, const void *buff, size_t size)
        } else {
                /* Yes, we're assuming the very first write is metadata. */
                /* It's header or metadata, copy and save it. */
-               block = (struct fileblock *)malloc(sizeof(*block));
+               block = malloc(sizeof(*block));
                memset(block, 0, sizeof(*block));
                block->size = (int)size;
                block->buff = malloc(size);
index 5cd1232b764c4e3c013fb7a7576d2c128305c613..3abd11358dfee41d0253050fd542b06f810ccec2 100644 (file)
@@ -134,7 +134,7 @@ _cset_add_filter(struct creation_set *cset, int program, const char *filter)
        struct filter_set *new_ptr;
        char *new_filter;
 
-       new_ptr = (struct filter_set *)realloc(cset->filters,
+       new_ptr = realloc(cset->filters,
            sizeof(*cset->filters) * (cset->filter_count + 1));
        if (new_ptr == NULL)
                lafe_errc(1, 0, "No memory");
index 8e1ec82436f8d61f5e83ade2654337505c1122fb..9a20224a2065f8b16bc0fa3f15b3c4671d5d1bc7 100644 (file)
@@ -48,6 +48,9 @@
 #endif
 
 #include <sys/types.h>  /* Windows requires this before sys/stat.h */
+#if !HAVE_SUSECONDS_T
+#define suseconds_t long
+#endif
 #include <sys/stat.h>
 
 #if HAVE_DIRENT_H
@@ -313,7 +316,7 @@ int assertion_non_empty_file(const char *, int, const char *);
 int assertion_set_nodump(const char *, int, const char *);
 int assertion_text_file_contents(const char *, int, const char *buff, const char *f);
 int assertion_umask(const char *, int, int);
-int assertion_utimes(const char *, int, const char *, long, long, long, long );
+int assertion_utimes(const char *, int, const char *, time_t, suseconds_t, time_t, suseconds_t);
 int assertion_version(const char*, int, const char *, const char *);
 
 void skipping_setup(const char *, int);
index ae5e74225cf2749af92933cd06af8846b77ba4ec..76fcd79406ff4456ae485b0c1b132512600887a7 100644 (file)
 #include <membership.h>
 #endif
 
+#ifndef nitems
+#define nitems(arr) (sizeof(arr) / sizeof((arr)[0]))
+#endif
+
 /*
  *
  * Windows support routines
@@ -236,10 +240,10 @@ my_CreateSymbolicLinkA(const char *linkname, const char *target,
        if (tlen == 0 || llen == 0)
                return (0);
 
-       tgt = malloc((tlen + 1) * sizeof(char));
+       tgt = malloc(tlen + 1);
        if (tgt == NULL)
                return (0);
-       src = malloc((llen + 1) * sizeof(char));
+       src = malloc(llen + 1);
        if (src == NULL) {
                free(tgt);
                return (0);
@@ -1240,16 +1244,19 @@ assertion_file_contains_lines_any_order(const char *file, int line,
        }
        expected_count = i;
        if (expected_count) {
-               expected = malloc(sizeof(char *) * expected_count);
+               expected = calloc(expected_count, sizeof(*expected));
                if (expected == NULL) {
                        failure_start(pathname, line, "Can't allocate memory");
                        failure_finish(NULL);
-                       free(expected);
-                       free(buff);
-                       return (0);
+                       goto cleanup;
                }
                for (i = 0; lines[i] != NULL; ++i) {
                        expected[i] = strdup(lines[i]);
+                       if (expected[i] == NULL) {
+                               failure_start(pathname, line, "Can't allocate memory");
+                               failure_finish(NULL);
+                               goto cleanup;
+                       }
                }
        }
 
@@ -1267,9 +1274,7 @@ assertion_file_contains_lines_any_order(const char *file, int line,
                if (actual == NULL) {
                        failure_start(pathname, line, "Can't allocate memory");
                        failure_finish(NULL);
-                       free(expected);
-                       free(buff);
-                       return (0);
+                       goto cleanup;
                }
                for (j = 0, p = buff; p < buff + buff_size;
                    p += 1 + strlen(p)) {
@@ -1282,8 +1287,6 @@ assertion_file_contains_lines_any_order(const char *file, int line,
 
        /* Erase matching lines from both lists */
        for (i = 0; i < expected_count; ++i) {
-               if (expected[i] == NULL)
-                       continue;
                for (j = 0; j < actual_count; ++j) {
                        if (actual[j] == NULL)
                                continue;
@@ -1306,9 +1309,9 @@ assertion_file_contains_lines_any_order(const char *file, int line,
                        ++actual_failure;
        }
        if (expected_failure == 0 && actual_failure == 0) {
-               free(buff);
-               free(expected);
                free(actual);
+               free(expected);
+               free(buff);
                return (1);
        }
        failure_start(file, line, "File doesn't match: %s", pathname);
@@ -1316,6 +1319,7 @@ assertion_file_contains_lines_any_order(const char *file, int line,
                if (expected[i] != NULL) {
                        logprintf("  Expected but not present: %s\n", expected[i]);
                        free(expected[i]);
+                       expected[i] = NULL;
                }
        }
        for (j = 0; j < actual_count; ++j) {
@@ -1323,9 +1327,15 @@ assertion_file_contains_lines_any_order(const char *file, int line,
                        logprintf("  Present but not expected: %s\n", actual[j]);
        }
        failure_finish(NULL);
-       free(buff);
-       free(expected);
+cleanup:
        free(actual);
+       if (expected != NULL) {
+               for (i = 0; i < expected_count; ++i)
+                       if (expected[i] != NULL)
+                               free(expected[i]);
+               free(expected);
+       }
+       free(buff);
        return (0);
 }
 
@@ -1769,16 +1779,17 @@ is_symlink(const char *file, int line,
            FILE_FLAG_OPEN_REPARSE_POINT;
 
        /* Replace slashes with backslashes in pathname */
-       pn = malloc((strlen(pathname) + 1) * sizeof(char));
-       p = pathname;
-       s = pn;
-       while(*p != '\0') {
-               if(*p == '/')
+       pn = malloc(strlen(pathname) + 1);
+       if (pn == NULL) {
+               failure_start(file, line, "Can't allocate memory");
+               failure_finish(NULL);
+               return (0);
+       }
+       for (p = pathname, s = pn; *p != '\0'; p++, s++) {
+               if (*p == '/')
                        *s = '\\';
                else
                        *s = *p;
-               p++;
-               s++;
        }
        *s = '\0';
 
@@ -2086,8 +2097,8 @@ assertion_umask(const char *file, int line, int mask)
 
 /* Set times, report failures. */
 int
-assertion_utimes(const char *file, int line,
-    const char *pathname, long at, long at_nsec, long mt, long mt_nsec)
+assertion_utimes(const char *file, int line, const char *pathname,
+    time_t at, suseconds_t at_nsec, time_t mt, suseconds_t mt_nsec)
 {
        int r;
 
@@ -2953,7 +2964,6 @@ setTestAcl(const char *path)
        acl_permset_t permset;
        const uid_t uid = 1;
        uuid_t uuid;
-       int i;
        const acl_perm_t acl_perms[] = {
                ACL_READ_DATA,
                ACL_WRITE_DATA,
@@ -2995,7 +3005,7 @@ setTestAcl(const char *path)
        failure("acl_get_permset() error: %s", strerror(errno));
        if (assertEqualInt(r, 0) == 0)
                goto testacl_free;
-       for (i = 0; i < (int)(sizeof(acl_perms) / sizeof(acl_perms[0])); i++) {
+       for (size_t i = 0; i < nitems(acl_perms); i++) {
                r = acl_add_perm(permset, acl_perms[i]);
                failure("acl_add_perm() error: %s", strerror(errno));
                if (assertEqualInt(r, 0) == 0)
@@ -3645,7 +3655,7 @@ test_run(int i, const char *tmpdir)
 static void
 usage(const char *program)
 {
-       static const int limit = sizeof(tests) / sizeof(tests[0]);
+       static const int limit = nitems(tests);
        int i;
 
        printf("Usage: %s [options] <test> <test> ...\n", program);
@@ -3877,10 +3887,11 @@ get_test_set(int *test_set, int limit, const char *test)
 int
 main(int argc, char **argv)
 {
-       static const int limit = sizeof(tests) / sizeof(tests[0]);
-       int test_set[sizeof(tests) / sizeof(tests[0])];
+       static const int limit = nitems(tests);
+       int test_set[nitems(tests)];
        int i = 0, j = 0, tests_run = 0, tests_failed = 0, option;
        size_t testprogdir_len;
+       size_t tmplen;
 #ifdef PROGRAM
        size_t tmp2_len;
 #endif
@@ -3925,7 +3936,7 @@ main(int argc, char **argv)
         */
        progname = p = argv[0];
        testprogdir_len = strlen(progname) + 1;
-       if ((testprogdir = (char *)malloc(testprogdir_len)) == NULL)
+       if ((testprogdir = malloc(testprogdir_len)) == NULL)
        {
                fprintf(stderr, "ERROR: Out of memory.");
                exit(1);
@@ -3953,7 +3964,7 @@ main(int argc, char **argv)
 #endif
        {
                /* Fixup path for relative directories. */
-               if ((testprogdir = (char *)realloc(testprogdir,
+               if ((testprogdir = realloc(testprogdir,
                        strlen(pwd) + 1 + strlen(testprogdir) + 1)) == NULL)
                {
                        fprintf(stderr, "ERROR: Out of memory.");
@@ -3980,6 +3991,9 @@ main(int argc, char **argv)
                tmp = getenv("TEMPDIR");
        else
                tmp = "/tmp";
+       tmplen = strlen(tmp);
+       while (tmplen > 0 && tmp[tmplen - 1] == '/')
+               tmplen--;
 
        /* Allow -d to be controlled through the environment. */
        if (getenv(ENVBASE "_DEBUG") != NULL)
@@ -4073,7 +4087,7 @@ main(int argc, char **argv)
        if (testprogfile == NULL)
        {
                tmp2_len = strlen(testprogdir) + 1 + strlen(PROGRAM) + 1;
-               if ((tmp2 = (char *)malloc(tmp2_len)) == NULL)
+               if ((tmp2 = malloc(tmp2_len)) == NULL)
                {
                        fprintf(stderr, "ERROR: Out of memory.");
                        exit(1);
@@ -4132,16 +4146,16 @@ main(int argc, char **argv)
 #endif
                strftime(tmpdir_timestamp, sizeof(tmpdir_timestamp),
                    "%Y-%m-%dT%H.%M.%S", tmptr);
-               if ((strlen(tmp) + 1 + strlen(progname) + 1 +
-                   strlen(tmpdir_timestamp) + 1 + 3) >
-                   (sizeof(tmpdir) / sizeof(char))) {
+               if (tmplen + 1 + strlen(progname) + 1 +
+                   strlen(tmpdir_timestamp) + 1 + 3 >=
+                   nitems(tmpdir)) {
                        fprintf(stderr,
                            "ERROR: Temp directory pathname too long\n");
                        exit(1);
                }
-               snprintf(tmpdir, sizeof(tmpdir), "%s/%s.%s-%03d", tmp,
-                   progname, tmpdir_timestamp, i);
-               if (assertMakeDir(tmpdir,0755))
+               snprintf(tmpdir, sizeof(tmpdir), "%.*s/%s.%s-%03d",
+                   (int)tmplen, tmp, progname, tmpdir_timestamp, i);
+               if (assertMakeDir(tmpdir, 0755))
                        break;
                if (i >= 999) {
                        fprintf(stderr,