Author: delphij
Date: Tue Sep  3 07:02:18 2019
New Revision: 351737
URL: https://svnweb.freebsd.org/changeset/base/351737

Log:
  MFC r351205: Use calloc().

Modified:
  stable/12/sbin/fsck_msdosfs/fat.c
Directory Properties:
  stable/12/   (props changed)

Modified: stable/12/sbin/fsck_msdosfs/fat.c
==============================================================================
--- stable/12/sbin/fsck_msdosfs/fat.c   Tue Sep  3 07:02:02 2019        
(r351736)
+++ stable/12/sbin/fsck_msdosfs/fat.c   Tue Sep  3 07:02:18 2019        
(r351737)
@@ -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) {
_______________________________________________
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