Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 19 Aug 2019 05:24:43 +0000 (UTC)
From:      Xin LI <delphij@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   svn commit: r351205 - head/sbin/fsck_msdosfs
Message-ID:  <201908190524.x7J5OhV4041712@repo.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: delphij
Date: Mon Aug 19 05:24:42 2019
New Revision: 351205
URL: https://svnweb.freebsd.org/changeset/base/351205

Log:
  Use calloc().
  
  MFC after:	2 weeks

Modified:
  head/sbin/fsck_msdosfs/fat.c

Modified: head/sbin/fsck_msdosfs/fat.c
==============================================================================
--- head/sbin/fsck_msdosfs/fat.c	Mon Aug 19 04:28:12 2019	(r351204)
+++ head/sbin/fsck_msdosfs/fat.c	Mon Aug 19 05:24:42 2019	(r351205)
@@ -54,10 +54,10 @@ static int _readfat(int, struct bootblock *, u_int, u_
  * 31...... ........ ........ .......0
  * rrrr1111 11111111 11111111 mmmmmmmm         FAT32 entry 0
  * rrrrsh11 11111111 11111111 11111xxx         FAT32 entry 1
- * 
+ *
  *                   11111111 mmmmmmmm         FAT16 entry 0
  *                   sh111111 11111xxx         FAT16 entry 1
- * 
+ *
  * r = reserved
  * m = BPB media ID byte
  * s = clean flag (1 = dismounted; 0 = still mounted)
@@ -166,11 +166,11 @@ static int
 _readfat(int fs, struct bootblock *boot, u_int no, u_char **buffer)
 {
 	off_t off;
-	size_t len;
 
-	*buffer = malloc(len = boot->FATsecs * boot->bpbBytesPerSec);
+	*buffer = calloc(boot->FATsecs, boot->bpbBytesPerSec);
 	if (*buffer == NULL) {
-		perr("No space for FAT sectors (%zu)", len);
+		perr("No space for FAT sectors (%zu)",
+		    (size_t)boot->FATsecs);
 		return 0;
 	}
 
@@ -205,20 +205,19 @@ readfat(int fs, struct bootblock *boot, u_int no, stru
 	u_char *buffer, *p;
 	cl_t cl;
 	int ret = FSOK;
-	size_t len;
 
 	boot->NumFree = boot->NumBad = 0;
 
 	if (!_readfat(fs, boot, no, &buffer))
 		return FSFATAL;
 
-	fat = malloc(len = boot->NumClusters * sizeof(struct fatEntry));
+	fat = calloc(boot->NumClusters, sizeof(struct fatEntry));
 	if (fat == NULL) {
-		perr("No space for FAT clusters (%zu)", len);
+		perr("No space for FAT clusters (%zu)",
+		    (size_t)boot->NumClusters);
 		free(buffer);
 		return FSFATAL;
 	}
-	(void)memset(fat, 0, len);
 
 	if (buffer[0] != boot->bpbMedia
 	    || buffer[1] != 0xff || buffer[2] != 0xff
@@ -566,12 +565,13 @@ writefat(int fs, struct bootblock *boot, struct fatEnt
 	off_t off;
 	int ret = FSOK;
 
-	buffer = malloc(fatsz = boot->FATsecs * boot->bpbBytesPerSec);
+	fatsz = boot->FATsecs * boot->bpbBytesPerSec;
+	buffer = calloc(boot->FATsecs, boot->bpbBytesPerSec);
 	if (buffer == NULL) {
-		perr("No space for FAT sectors (%zu)", fatsz);
+		perr("No space for FAT sectors (%zu)",
+		    (size_t)boot->FATsecs);
 		return FSFATAL;
 	}
-	memset(buffer, 0, fatsz);
 	boot->NumFree = 0;
 	p = buffer;
 	if (correct_fat) {



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201908190524.x7J5OhV4041712>