]> git.proxmox.com Git - mirror_zfs.git/commitdiff
Fix calloc(3) arguments order
authorTomohiro Kusumi <kusumi.tomohiro@gmail.com>
Thu, 12 Apr 2018 17:50:39 +0000 (02:50 +0900)
committerBrian Behlendorf <behlendorf1@llnl.gov>
Thu, 12 Apr 2018 17:50:39 +0000 (10:50 -0700)
calloc(3) takes `nelem` (or `nmemb` in glibc) first, and then size of
elements.  No difference expected for having these in reverse order,
however should follow the standard.

http://pubs.opengroup.org/onlinepubs/009695399/functions/calloc.html

Reviewed-by: Tony Hutter <hutter2@llnl.gov>
Reviewed-by: Brian Behlendorf <behlendorf1@llnl.gov>
Signed-off-by: Tomohiro Kusumi <kusumi.tomohiro@osnexus.com>
Closes #7405

lib/libefi/rdwr_efi.c
lib/libshare/libshare.c
lib/libspl/mkdirp.c
lib/libzfs/libzfs_dataset.c
lib/libzfs/libzfs_import.c
tests/zfs-tests/cmd/mkfile/mkfile.c

index 7935047ebfcd811dcb002344ec5a9ed51396933b..e8a5ddd318bc823a1c1e53fdfe902ab955822527 100644 (file)
@@ -218,7 +218,7 @@ efi_get_info(int fd, struct dk_cinfo *dki_info)
 
        memset(dki_info, 0, sizeof (*dki_info));
 
 
        memset(dki_info, 0, sizeof (*dki_info));
 
-       path = calloc(PATH_MAX, 1);
+       path = calloc(1, PATH_MAX);
        if (path == NULL)
                goto error;
 
        if (path == NULL)
                goto error;
 
@@ -403,7 +403,7 @@ efi_alloc_and_init(int fd, uint32_t nparts, struct dk_gpt **vtoc)
        length = sizeof (struct dk_gpt) +
            sizeof (struct dk_part) * (nparts - 1);
 
        length = sizeof (struct dk_gpt) +
            sizeof (struct dk_part) * (nparts - 1);
 
-       if ((*vtoc = calloc(length, 1)) == NULL)
+       if ((*vtoc = calloc(1, length)) == NULL)
                return (-1);
 
        vptr = *vtoc;
                return (-1);
 
        vptr = *vtoc;
@@ -440,7 +440,7 @@ efi_alloc_and_read(int fd, struct dk_gpt **vtoc)
        nparts = EFI_MIN_ARRAY_SIZE / sizeof (efi_gpe_t);
        length = (int) sizeof (struct dk_gpt) +
            (int) sizeof (struct dk_part) * (nparts - 1);
        nparts = EFI_MIN_ARRAY_SIZE / sizeof (efi_gpe_t);
        length = (int) sizeof (struct dk_gpt) +
            (int) sizeof (struct dk_part) * (nparts - 1);
-       if ((*vtoc = calloc(length, 1)) == NULL)
+       if ((*vtoc = calloc(1, length)) == NULL)
                return (VT_ERROR);
 
        (*vtoc)->efi_nparts = nparts;
                return (VT_ERROR);
 
        (*vtoc)->efi_nparts = nparts;
index 022df016f26d895ea9fdd80aa2cbc7e898fc345b..0965911cf0a62670d98996d417d4b9b5c83cd345 100644 (file)
@@ -61,7 +61,7 @@ register_fstype(const char *name, const sa_share_ops_t *ops)
 {
        sa_fstype_t *fstype;
 
 {
        sa_fstype_t *fstype;
 
-       fstype = calloc(sizeof (sa_fstype_t), 1);
+       fstype = calloc(1, sizeof (sa_fstype_t));
 
        if (fstype == NULL)
                return (NULL);
 
        if (fstype == NULL)
                return (NULL);
@@ -83,7 +83,7 @@ sa_init(int init_service)
 {
        sa_handle_impl_t impl_handle;
 
 {
        sa_handle_impl_t impl_handle;
 
-       impl_handle = calloc(sizeof (struct sa_handle_impl), 1);
+       impl_handle = calloc(1, sizeof (struct sa_handle_impl));
 
        if (impl_handle == NULL)
                return (NULL);
 
        if (impl_handle == NULL)
                return (NULL);
@@ -713,7 +713,7 @@ alloc_share(const char *sharepath)
 {
        sa_share_impl_t impl_share;
 
 {
        sa_share_impl_t impl_share;
 
-       impl_share = calloc(sizeof (struct sa_share_impl), 1);
+       impl_share = calloc(1, sizeof (struct sa_share_impl));
 
        if (impl_share == NULL)
                return (NULL);
 
        if (impl_share == NULL)
                return (NULL);
@@ -725,7 +725,7 @@ alloc_share(const char *sharepath)
                return (NULL);
        }
 
                return (NULL);
        }
 
-       impl_share->fsinfo = calloc(sizeof (sa_share_fsinfo_t), fstypes_count);
+       impl_share->fsinfo = calloc(fstypes_count, sizeof (sa_share_fsinfo_t));
 
        if (impl_share->fsinfo == NULL) {
                free(impl_share->sharepath);
 
        if (impl_share->fsinfo == NULL) {
                free(impl_share->sharepath);
index 2f091883adf5be430c6aa95ec94f958abfb5d281..54174175200e78ee1b4177ee627e5ad1a46890ca 100644 (file)
@@ -166,7 +166,7 @@ simplify(const char *str)
 
        mbPathlen = strlen(mbPath);
 
 
        mbPathlen = strlen(mbPath);
 
-       if ((wcPath = calloc(sizeof (wchar_t), mbPathlen+1)) == NULL) {
+       if ((wcPath = calloc(mbPathlen+1, sizeof (wchar_t))) == NULL) {
                free(mbPath);
                return (NULL);
        }
                free(mbPath);
                return (NULL);
        }
index acfcb7491deae7dc23fcdec66d021206e5cfe0d8..65834b6d1710a2467d56e579d64be432f9daf575 100644 (file)
@@ -466,7 +466,7 @@ make_dataset_handle(libzfs_handle_t *hdl, const char *path)
 {
        zfs_cmd_t zc = {"\0"};
 
 {
        zfs_cmd_t zc = {"\0"};
 
-       zfs_handle_t *zhp = calloc(sizeof (zfs_handle_t), 1);
+       zfs_handle_t *zhp = calloc(1, sizeof (zfs_handle_t));
 
        if (zhp == NULL)
                return (NULL);
 
        if (zhp == NULL)
                return (NULL);
@@ -493,7 +493,7 @@ make_dataset_handle(libzfs_handle_t *hdl, const char *path)
 zfs_handle_t *
 make_dataset_handle_zc(libzfs_handle_t *hdl, zfs_cmd_t *zc)
 {
 zfs_handle_t *
 make_dataset_handle_zc(libzfs_handle_t *hdl, zfs_cmd_t *zc)
 {
-       zfs_handle_t *zhp = calloc(sizeof (zfs_handle_t), 1);
+       zfs_handle_t *zhp = calloc(1, sizeof (zfs_handle_t));
 
        if (zhp == NULL)
                return (NULL);
 
        if (zhp == NULL)
                return (NULL);
@@ -510,7 +510,7 @@ make_dataset_handle_zc(libzfs_handle_t *hdl, zfs_cmd_t *zc)
 zfs_handle_t *
 make_dataset_simple_handle_zc(zfs_handle_t *pzhp, zfs_cmd_t *zc)
 {
 zfs_handle_t *
 make_dataset_simple_handle_zc(zfs_handle_t *pzhp, zfs_cmd_t *zc)
 {
-       zfs_handle_t *zhp = calloc(sizeof (zfs_handle_t), 1);
+       zfs_handle_t *zhp = calloc(1, sizeof (zfs_handle_t));
 
        if (zhp == NULL)
                return (NULL);
 
        if (zhp == NULL)
                return (NULL);
@@ -527,7 +527,7 @@ make_dataset_simple_handle_zc(zfs_handle_t *pzhp, zfs_cmd_t *zc)
 zfs_handle_t *
 zfs_handle_dup(zfs_handle_t *zhp_orig)
 {
 zfs_handle_t *
 zfs_handle_dup(zfs_handle_t *zhp_orig)
 {
-       zfs_handle_t *zhp = calloc(sizeof (zfs_handle_t), 1);
+       zfs_handle_t *zhp = calloc(1, sizeof (zfs_handle_t));
 
        if (zhp == NULL)
                return (NULL);
 
        if (zhp == NULL)
                return (NULL);
@@ -607,7 +607,7 @@ zfs_handle_t *
 make_bookmark_handle(zfs_handle_t *parent, const char *path,
     nvlist_t *bmark_props)
 {
 make_bookmark_handle(zfs_handle_t *parent, const char *path,
     nvlist_t *bmark_props)
 {
-       zfs_handle_t *zhp = calloc(sizeof (zfs_handle_t), 1);
+       zfs_handle_t *zhp = calloc(1, sizeof (zfs_handle_t));
 
        if (zhp == NULL)
                return (NULL);
 
        if (zhp == NULL)
                return (NULL);
index 67bf9b0be381a2b94ff4781ca14961e7768103bc..cc9a52a3eabb73b86dae34737d20e62623599717 100644 (file)
@@ -1673,7 +1673,7 @@ zpool_clear_label(int fd)
                return (0);
        size = P2ALIGN_TYPED(statbuf.st_size, sizeof (vdev_label_t), uint64_t);
 
                return (0);
        size = P2ALIGN_TYPED(statbuf.st_size, sizeof (vdev_label_t), uint64_t);
 
-       if ((label = calloc(sizeof (vdev_label_t), 1)) == NULL)
+       if ((label = calloc(1, sizeof (vdev_label_t))) == NULL)
                return (-1);
 
        for (l = 0; l < VDEV_LABELS; l++) {
                return (-1);
 
        for (l = 0; l < VDEV_LABELS; l++) {
index 000249f112e56a4c9a7b511240fbd0b3d5ebe853..7ebf7bbcf83a33f4ea6723e92c3a28f9cd6fbfec 100644 (file)
@@ -194,7 +194,7 @@ main(int argc, char **argv)
                                if (buf)
                                        free(buf);
                                bufsz = (size_t)st.st_blksize;
                                if (buf)
                                        free(buf);
                                bufsz = (size_t)st.st_blksize;
-                               buf = calloc(bufsz, 1);
+                               buf = calloc(1, bufsz);
                                if (buf == NULL) {
                                        (void) fprintf(stderr, gettext(
                                            "Could not allocate buffer of"
                                if (buf == NULL) {
                                        (void) fprintf(stderr, gettext(
                                            "Could not allocate buffer of"