]> git.ipfire.org Git - thirdparty/libarchive.git/commitdiff
Use calloc arguments that correspond with the variable's true purpose (#1993)
authorAtariDreams <83477269+AtariDreams@users.noreply.github.com>
Wed, 18 Oct 2023 18:29:11 +0000 (14:29 -0400)
committerGitHub <noreply@github.com>
Wed, 18 Oct 2023 18:29:11 +0000 (11:29 -0700)
First argument is number of times to allocate a region of the second
size, which is the size of the element being allocated.

18 files changed:
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_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_rar.c
libarchive/archive_write.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_zip_nested.c
libarchive/test/test_write_filter_lz4.c
libarchive/test/test_write_filter_lzop.c
test_utils/test_main.c

index 9158e668eb42bdc7cc26c8689e3b66402bd2fd81..04691af17d8036e8b206ce7339de9d8a0d35f8c4 100644 (file)
@@ -192,7 +192,7 @@ bzip2_reader_init(struct archive_read_filter *self)
        self->code = ARCHIVE_FILTER_BZIP2;
        self->name = "bzip2";
 
-       state = (struct private_data *)calloc(sizeof(*state), 1);
+       state = (struct private_data *)calloc(1, sizeof(*state));
        out_block = (unsigned char *)malloc(out_block_size);
        if (state == NULL || out_block == NULL) {
                archive_set_error(&self->archive->archive, ENOMEM,
index 05b80a576ac1c4043be3fbfc756cfa61b54dde3d..8ce4a52bf880ddc3cbaec7f4b03dc69474158940 100644 (file)
@@ -218,7 +218,7 @@ compress_bidder_init(struct archive_read_filter *self)
        self->code = ARCHIVE_FILTER_COMPRESS;
        self->name = "compress (.Z)";
 
-       state = (struct private_data *)calloc(sizeof(*state), 1);
+       state = (struct private_data *)calloc(1, sizeof(*state));
        out_block = malloc(out_block_size);
        if (state == NULL || out_block == NULL) {
                free(out_block);
index 4135a6361802e6a281c50c6b366aecb0b46b9d0c..9b9be2a42100bb664c84149750e73a37f6482af4 100644 (file)
@@ -310,7 +310,7 @@ gzip_bidder_init(struct archive_read_filter *self)
        self->code = ARCHIVE_FILTER_GZIP;
        self->name = "gzip";
 
-       state = (struct private_data *)calloc(sizeof(*state), 1);
+       state = (struct private_data *)calloc(1, sizeof(*state));
        out_block = (unsigned char *)malloc(out_block_size);
        if (state == NULL || out_block == NULL) {
                free(out_block);
index d0fc1a83e462e99c26a3dfb7cdec75e17a96fd56..d2c5f1b4d8e6bec48a5ff7e115c59bacf0bc4a0d 100644 (file)
@@ -225,7 +225,7 @@ lz4_reader_init(struct archive_read_filter *self)
        self->code = ARCHIVE_FILTER_LZ4;
        self->name = "lz4";
 
-       state = (struct private_data *)calloc(sizeof(*state), 1);
+       state = (struct private_data *)calloc(1, sizeof(*state));
        if (state == NULL) {
                archive_set_error(&self->archive->archive, ENOMEM,
                    "Can't allocate data for lz4 decompression");
index 4ebdd3bf3eb1730d191dbace59ffb86a389499c5..87c741786bdd57196acaf5db5068c4ed53086ebf 100644 (file)
@@ -187,7 +187,7 @@ lzop_bidder_init(struct archive_read_filter *self)
        self->code = ARCHIVE_FILTER_LZOP;
        self->name = "lzop";
 
-       state = (struct read_lzop *)calloc(sizeof(*state), 1);
+       state = (struct read_lzop *)calloc(1, sizeof(*state));
        if (state == NULL) {
                archive_set_error(&self->archive->archive, ENOMEM,
                    "Can't allocate data for lzop decompression");
index 67a979cd78f6022abea69e23cb564d394fe91531..87e9f2ec19393eb98def9a1a93053f407c57d74d 100644 (file)
@@ -141,7 +141,7 @@ rpm_bidder_init(struct archive_read_filter *self)
        self->code = ARCHIVE_FILTER_RPM;
        self->name = "rpm";
 
-       rpm = (struct rpm *)calloc(sizeof(*rpm), 1);
+       rpm = (struct rpm *)calloc(1, sizeof(*rpm));
        if (rpm == NULL) {
                archive_set_error(&self->archive->archive, ENOMEM,
                    "Can't allocate data for rpm");
index cd79638e739dc8e2f13154b6c2b6c93822597904..be5b2b28f342c657e5edd55a0c29ad27164a7e3e 100644 (file)
@@ -374,7 +374,7 @@ uudecode_bidder_init(struct archive_read_filter *self)
        self->code = ARCHIVE_FILTER_UU;
        self->name = "uu";
 
-       uudecode = (struct uudecode *)calloc(sizeof(*uudecode), 1);
+       uudecode = (struct 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 e313d39c0cf2e91b37a0039c474f400a249c5323..2b3cc2c5527730b4333cd7829597deacd6f7934a 100644 (file)
@@ -478,7 +478,7 @@ xz_lzma_bidder_init(struct archive_read_filter *self)
        struct private_data *state;
        int ret;
 
-       state = (struct private_data *)calloc(sizeof(*state), 1);
+       state = (struct private_data *)calloc(1, sizeof(*state));
        out_block = (unsigned char *)malloc(out_block_size);
        if (state == NULL || out_block == NULL) {
                archive_set_error(&self->archive->archive, ENOMEM,
index 1959b5ac39914741d601e2480568ddbe0f8f0ac9..e18662c0f9dee3b7a84137d67143327053c03fcc 100644 (file)
@@ -177,7 +177,7 @@ zstd_bidder_init(struct archive_read_filter *self)
        self->code = ARCHIVE_FILTER_ZSTD;
        self->name = "zstd";
 
-       state = (struct private_data *)calloc(sizeof(*state), 1);
+       state = (struct private_data *)calloc(1, sizeof(*state));
        out_block = (unsigned char *)malloc(out_block_size);
        dstream = ZSTD_createDStream();
 
index 16b6e6eed8df7574b5b7ffef1b9ac15bc637345d..99a11d1700743424158d7a2fb5ed265fe49d548b 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(sizeof(*rar), 1);
+  rar = (struct rar *)calloc(1, sizeof(*rar));
   if (rar == NULL)
   {
     archive_set_error(&a->archive, ENOMEM, "Can't allocate rar data");
index ec3c95c56685eefea63cb58e4017e038058ea219..906cc3a5c717c06cfd9fd3f93c636ed357dd1e41 100644 (file)
@@ -115,7 +115,7 @@ archive_write_new(void)
 
        /* Initialize a block of nulls for padding purposes. */
        a->null_length = 1024;
-       nulls = (unsigned char *)calloc(1, a->null_length);
+       nulls = (unsigned char *)calloc(a->null_length, sizeof(unsigned char));
        if (nulls == NULL) {
                free(a);
                return (NULL);
index 9962cf7fdf33f334f2c416882d5633c095d9186f..7c7aec68de3c4df3cc8d6be74294ea3dd43a90a0 100644 (file)
@@ -185,7 +185,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(1, BLOCK_SIZE)) == NULL)
+      if ((mydata->buffer = (void*)calloc(BLOCK_SIZE, 1)) == NULL)
         return (ARCHIVE_FAILED);
     }
   }
@@ -287,7 +287,7 @@ test_customized_multiple_data_objects(void)
       return;
     }
     assert((mydata->filename =
-      (char *)calloc(1, strlen(filename) + 1)) != NULL);
+      (char *)calloc(strlen(filename) + 1, sizeof(char))) != NULL);
     if (mydata->filename == NULL) {
       free(mydata);
       assertEqualInt(ARCHIVE_OK, archive_read_free(a));
index 7fa743ba9ed2a07fc38f9d135187c9d42d7f5908..6331f7f00ce8483338bfcb4e553b2810bf1121e0 100644 (file)
@@ -406,7 +406,7 @@ DEFINE_TEST(test_archive_string_sort)
 
   srand((unsigned int)time(NULL));
   size = sizeof(strings) / sizeof(char *);
-  assert((test_strings = (char **)calloc(1, sizeof(strings))) != NULL);
+  assert((test_strings = (char **)calloc(size, sizeof(char *))) != NULL);
   for (i = 0; i < (size - 1); i++)
     assert((test_strings[i] = strdup(strings[i])) != NULL);
 
index 49f91ac554dcaa5467035670e54f59137b8d62c2..9e145fffaadd1d758142f77eabf6a3f8a99c64b6 100644 (file)
@@ -38,7 +38,7 @@ test_filter_by_name(const char *filter_name, int filter_code,
        char *buff;
        int r;
 
-       assert((buff = calloc(1, buffsize)) != NULL);
+       assert((buff = calloc(buffsize, sizeof(char))) != NULL);
        if (buff == NULL)
                return;
 
index 4418fc4f25022772d7f50058a3958f42dce39c9f..448180fb2b28feecafdab54e968fb806722b1cae 100644 (file)
@@ -50,7 +50,7 @@ DEFINE_TEST(test_read_format_zip_nested)
 
        /* Save contents of inner Zip. */
        innerLength = (size_t)archive_entry_size(ae);
-       inner = calloc(innerLength, 1);
+       inner = calloc(innerLength, sizeof(char));
        assertEqualInt(innerLength, archive_read_data(a, inner, innerLength));
 
        assertEqualIntA(a, ARCHIVE_OK, archive_read_next_header(a, &ae));
index 071fee41dd95648394fb2fa06a9b58f0447e921a..df23292e873baea1c711eafaa7e620668941949f 100644 (file)
@@ -62,7 +62,7 @@ DEFINE_TEST(test_write_filter_lz4)
        assert(NULL != (buff = (char *)malloc(buffsize)));
 
        datasize = 10000;
-       assert(NULL != (data = (char *)calloc(1, datasize)));
+       assert(NULL != (data = (char *)calloc(datasize, 1)));
        filecount = 10;
 
        /*
@@ -306,7 +306,7 @@ test_options(const char *options)
        assert(NULL != (buff = (char *)malloc(buffsize)));
 
        datasize = 10000;
-       assert(NULL != (data = (char *)calloc(1, datasize)));
+       assert(NULL != (data = (char *)calloc(datasize, 1)));
        filecount = 10;
 
        /*
index 18fc332b44ffee84cbcab6faa5ba754f0e3539c9..6b84e4b18e195959f1e8147df843fc922236efd9 100644 (file)
@@ -57,7 +57,7 @@ DEFINE_TEST(test_write_filter_lzop)
        assert(NULL != (buff = (char *)malloc(buffsize)));
 
        datasize = 10000;
-       assert(NULL != (data = (char *)calloc(1, datasize)));
+       assert(NULL != (data = (char *)calloc(datasize, 1)));
        filecount = 10;
 
        /*
index e4b884ee3c446a267be7f93cecd7eec2cb7a0a71..ffc33e4e05a6d60485851dd9fb7262105e17cd63 100644 (file)
@@ -1245,7 +1245,7 @@ assertion_file_contains_lines_any_order(const char *file, int line,
                c = *p;
        }
        if (actual_count) {
-               actual = calloc(sizeof(char *), actual_count);
+               actual = calloc(actual_count, sizeof(char *));
                if (actual == NULL) {
                        failure_start(pathname, line, "Can't allocate memory");
                        failure_finish(NULL);