Print this page
10100 Illumos is confused about calloc() arguments

@@ -22,10 +22,11 @@
 /*
  * Copyright (c) 2002, 2010, Oracle and/or its affiliates. All rights reserved.
  * Copyright 2015 Nexenta Systems, Inc.  All rights reserved.
  * Copyright 2014 Toomas Soome <tsoome@me.com>
  * Copyright 2018 OmniOS Community Edition (OmniOSce) Association.
+ * Copyright (c) 2018, Joyent, Inc.
  */
 
 #include <stdio.h>
 #include <stdlib.h>
 #include <errno.h>

@@ -186,11 +187,11 @@
         }
 
         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;
 
         vptr->efi_version = EFI_VERSION_CURRENT;

@@ -227,11 +228,11 @@
         int                     i;
 
         if (read_disk_info(fd, &capacity, &lbsize) != 0)
                 return (VT_ERROR);
 
-        if ((mbr = calloc(lbsize, 1)) == NULL)
+        if ((mbr = calloc(1, lbsize)) == NULL)
                 return (VT_ERROR);
 
         if ((ioctl(fd, DKIOCGMBOOT, (caddr_t)mbr)) == -1) {
                 free(mbr);
                 return (VT_ERROR);

@@ -254,11 +255,11 @@
 
         /* figure out the number of entries that would fit into 16K */
         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;
         rval = efi_read(fd, *vtoc);
 

@@ -421,11 +422,11 @@
                         label_len += disk_info.dki_lbsize;
                         label_len &= ~(disk_info.dki_lbsize - 1);
                 }
         }
 
-        if ((dk_ioc.dki_data = calloc(label_len, 1)) == NULL)
+        if ((dk_ioc.dki_data = calloc(1, label_len)) == NULL)
                 return (VT_ERROR);
 
         dk_ioc.dki_length = disk_info.dki_lbsize;
         user_length = vtoc->efi_nparts;
         efi = dk_ioc.dki_data;

@@ -1018,11 +1019,11 @@
          * Backup GPT header is located on the block after GUID
          * partition entry array. Here, we calculate the address
          * for backup GPT header.
          */
         lba_backup_gpt_hdr = vtoc->efi_last_u_lba + 1 + nblocks;
-        if ((dk_ioc.dki_data = calloc(dk_ioc.dki_length, 1)) == NULL)
+        if ((dk_ioc.dki_data = calloc(1, dk_ioc.dki_length)) == NULL)
                 return (VT_ERROR);
 
         efi = dk_ioc.dki_data;
 
         /* stuff user's input into EFI struct */