From owner-svn-src-all@freebsd.org Mon Aug 19 05:24:43 2019 Return-Path: Delivered-To: svn-src-all@mailman.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.nyi.freebsd.org (Postfix) with ESMTP id 82B1EA8E49; Mon, 19 Aug 2019 05:24:43 +0000 (UTC) (envelope-from delphij@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) server-signature RSA-PSS (4096 bits) client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 46Bj6M2hKXz4LBj; Mon, 19 Aug 2019 05:24:43 +0000 (UTC) (envelope-from delphij@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 2BC2DDC73; Mon, 19 Aug 2019 05:24:43 +0000 (UTC) (envelope-from delphij@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id x7J5Oh4p041713; Mon, 19 Aug 2019 05:24:43 GMT (envelope-from delphij@FreeBSD.org) Received: (from delphij@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id x7J5OhV4041712; Mon, 19 Aug 2019 05:24:43 GMT (envelope-from delphij@FreeBSD.org) Message-Id: <201908190524.x7J5OhV4041712@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: delphij set sender to delphij@FreeBSD.org using -f From: Xin LI Date: Mon, 19 Aug 2019 05:24:43 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r351205 - head/sbin/fsck_msdosfs X-SVN-Group: head X-SVN-Commit-Author: delphij X-SVN-Commit-Paths: head/sbin/fsck_msdosfs X-SVN-Commit-Revision: 351205 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 19 Aug 2019 05:24:43 -0000 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) {