svn commit: r355513 - head/sbin/newfs_msdos

Xin LI delphij at FreeBSD.org
Sun Dec 8 01:20:38 UTC 2019


Author: delphij
Date: Sun Dec  8 01:20:37 2019
New Revision: 355513
URL: https://svnweb.freebsd.org/changeset/base/355513

Log:
  Fix a couple of minor issues with newfs_msdos:
  
   - Do not unnecessarily strdup().
   - Check return value of getdiskinfo(), if it failed, bail out.
  
  Reviewed by:	imp
  MFC after:	2 weeks
  Differential Revision:	https://reviews.freebsd.org/D22729

Modified:
  head/sbin/newfs_msdos/mkfs_msdos.c
  head/sbin/newfs_msdos/newfs_msdos.c

Modified: head/sbin/newfs_msdos/mkfs_msdos.c
==============================================================================
--- head/sbin/newfs_msdos/mkfs_msdos.c	Sun Dec  8 01:17:38 2019	(r355512)
+++ head/sbin/newfs_msdos/mkfs_msdos.c	Sun Dec  8 01:20:37 2019	(r355513)
@@ -318,7 +318,8 @@ mkfs_msdos(const char *fname, const char *dtype, const
 	bpb.bpbHiddenSecs = o.hidden_sectors;
     if (!(o.floppy || (o.drive_heads && o.sectors_per_track &&
 	o.bytes_per_sector && o.size && o.hidden_sectors_set))) {
-	getdiskinfo(fd, fname, dtype, o.hidden_sectors_set, &bpb);
+	if (getdiskinfo(fd, fname, dtype, o.hidden_sectors_set, &bpb) == -1)
+		goto done;
 	bpb.bpbHugeSectors -= (o.offset / bpb.bpbBytesPerSec);
 	if (bpb.bpbSecPerClust == 0) {	/* set defaults */
 	    if (bpb.bpbHugeSectors <= 6000)	/* about 3MB -> 512 bytes */
@@ -423,10 +424,7 @@ mkfs_msdos(const char *fname, const char *dtype, const
 	bname = o.bootstrap;
 	if (!strchr(bname, '/')) {
 	    snprintf(buf, sizeof(buf), "/boot/%s", bname);
-	    if (!(bname = strdup(buf))) {
-		warn(NULL);
-		goto done;
-	    }
+	    bname = buf;
 	}
 	if ((fd1 = open(bname, O_RDONLY)) == -1 || fstat(fd1, &sb)) {
 	    warn("%s", bname);

Modified: head/sbin/newfs_msdos/newfs_msdos.c
==============================================================================
--- head/sbin/newfs_msdos/newfs_msdos.c	Sun Dec  8 01:17:38 2019	(r355512)
+++ head/sbin/newfs_msdos/newfs_msdos.c	Sun Dec  8 01:20:37 2019	(r355513)
@@ -185,8 +185,7 @@ main(int argc, char *argv[])
     fname = *argv++;
     if (!o.create_size && !strchr(fname, '/')) {
 	snprintf(buf, sizeof(buf), "%s%s", _PATH_DEV, fname);
-	if (!(fname = strdup(buf)))
-	    err(1, NULL);
+	fname = buf;
     }
     dtype = *argv;
     exit(!!mkfs_msdos(fname, dtype, &o));


More information about the svn-src-head mailing list