Date: Fri, 21 Apr 2017 20:03:08 +0000 (UTC) From: "Pedro F. Giffuni" <pfg@FreeBSD.org> To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-11@freebsd.org Subject: svn commit: r317268 - stable/11/usr.bin/mkimg Message-ID: <201704212003.v3LK38RA074853@repo.freebsd.org>
next in thread | raw e-mail | index | archive | help
Author: pfg Date: Fri Apr 21 20:03:08 2017 New Revision: 317268 URL: https://svnweb.freebsd.org/changeset/base/317268 Log: MFC r302664: 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). Requested by: manu Modified: stable/11/usr.bin/mkimg/vmdk.c Directory Properties: stable/11/ (props changed) Modified: stable/11/usr.bin/mkimg/vmdk.c ============================================================================== --- stable/11/usr.bin/mkimg/vmdk.c Fri Apr 21 19:53:52 2017 (r317267) +++ stable/11/usr.bin/mkimg/vmdk.c Fri Apr 21 20:03:08 2017 (r317268) @@ -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) {
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201704212003.v3LK38RA074853>