Author: pfg
Date: Tue Jul 12 15:46:53 2016
New Revision: 302664
URL: https://svnweb.freebsd.org/changeset/base/302664

Log:
  mkimg(1): minor cleanups with argument order in calloc(3).
  
  Generally the first argument in calloc is supposed to stand for a count
  and the second for a size. Try to make that consistent. While here,
  attempt to make some use of the overflow detection capability in
  calloc(3).

Modified:
  head/usr.bin/mkimg/vmdk.c

Modified: head/usr.bin/mkimg/vmdk.c
==============================================================================
--- head/usr.bin/mkimg/vmdk.c   Tue Jul 12 13:12:01 2016        (r302663)
+++ head/usr.bin/mkimg/vmdk.c   Tue Jul 12 15:46:53 2016        (r302664)
@@ -149,7 +149,7 @@ vmdk_write(int fd)
        gdsz = (ngts * sizeof(uint32_t) + VMDK_SECTOR_SIZE - 1) &
            ~(VMDK_SECTOR_SIZE - 1);
 
-       gd = calloc(gdsz, 1);
+       gd = calloc(1, gdsz);
        if (gd == NULL) {
                free(desc);
                return (ENOMEM);
@@ -161,7 +161,7 @@ vmdk_write(int fd)
                sec += VMDK_NGTES * sizeof(uint32_t) / VMDK_SECTOR_SIZE;
        }
 
-       rgd = calloc(gdsz, 1);
+       rgd = calloc(1, gdsz);
        if (rgd == NULL) {
                free(gd);
                free(desc);
@@ -183,14 +183,14 @@ vmdk_write(int fd)
        le64enc(&hdr.overhead, sec);
        be32enc(&hdr.nl_test, VMDK_NL_TEST);
 
-       gtsz = ngts * VMDK_NGTES * sizeof(uint32_t);
-       gt = calloc(gtsz, 1);
+       gt = calloc(ngts, VMDK_NGTES * sizeof(uint32_t));
        if (gt == NULL) {
                free(rgd);
                free(gd);
                free(desc);
                return (ENOMEM);
        }
+       gtsz = ngts * VMDK_NGTES * sizeof(uint32_t);
 
        cursec = sec;
        blkcnt = (grainsz * VMDK_SECTOR_SIZE) / secsz;
@@ -225,7 +225,7 @@ vmdk_write(int fd)
        cur = VMDK_SECTOR_SIZE + desc_len + (gdsz + gtsz) * 2;
        lim = sec * VMDK_SECTOR_SIZE;
        if (cur < lim) {
-               buf = calloc(VMDK_SECTOR_SIZE, 1);
+               buf = calloc(1, VMDK_SECTOR_SIZE);
                if (buf == NULL)
                        error = ENOMEM;
                while (!error && cur < lim) {
_______________________________________________
svn-src-all@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-all
To unsubscribe, send any mail to "svn-src-all-unsubscr...@freebsd.org"

Reply via email to