Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 9 May 2019 11:04:10 +0000 (UTC)
From:      Toomas Soome <tsoome@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   svn commit: r347389 - head/stand/common
Message-ID:  <201905091104.x49B4ANp030950@repo.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: tsoome
Date: Thu May  9 11:04:10 2019
New Revision: 347389
URL: https://svnweb.freebsd.org/changeset/base/347389

Log:
  loader: ptable_print() needs two tabs sometimes
  
  Since the partition/slice names do vary in length, check the length
  of the fixed part of the line against 3 * 8, if the lenth is less than
  3 tab stops, print out extra tab.
  
  use snprintf() instead of sprintf.

Modified:
  head/stand/common/disk.c

Modified: head/stand/common/disk.c
==============================================================================
--- head/stand/common/disk.c	Thu May  9 10:37:57 2019	(r347388)
+++ head/stand/common/disk.c	Thu May  9 11:04:10 2019	(r347389)
@@ -75,7 +75,7 @@ display_size(uint64_t size, u_int sectorsize)
 		size /= 1024;
 		unit = 'M';
 	}
-	sprintf(buf, "%4ld%cB", (long)size, unit);
+	snprintf(buf, sizeof(buf), "%4ld%cB", (long)size, unit);
 	return (buf);
 }
 
@@ -118,11 +118,24 @@ ptable_print(void *arg, const char *pname, const struc
 	od = (struct open_disk *)pa->dev->dd.d_opendata;
 	sectsize = od->sectorsize;
 	partsize = part->end - part->start + 1;
-	sprintf(line, "  %s%s: %s\t%s\n", pa->prefix, pname,
-	    parttype2str(part->type),
-	    pa->verbose ? display_size(partsize, sectsize) : "");
+	snprintf(line, sizeof(line), "  %s%s: %s", pa->prefix, pname,
+	    parttype2str(part->type));
 	if (pager_output(line))
-		return 1;
+		return (1);
+
+	if (pa->verbose) {
+		/* Emit extra tab when the line is shorter than 3 tab stops */
+		if (strlen(line) < 24)
+			(void) pager_output("\t");
+
+		snprintf(line, sizeof(line), "\t%s",
+		    display_size(partsize, sectsize));
+		if (pager_output(line))
+			return (1);
+	}
+	if (pager_output("\n"))
+		return (1);
+
 	res = 0;
 	if (part->type == PART_FREEBSD) {
 		/* Open slice with BSD label */
@@ -133,7 +146,8 @@ ptable_print(void *arg, const char *pname, const struc
 		if (disk_open(&dev, partsize, sectsize) == 0) {
 			table = ptable_open(&dev, partsize, sectsize, ptblread);
 			if (table != NULL) {
-				sprintf(line, "  %s%s", pa->prefix, pname);
+				snprintf(line, sizeof(line), "  %s%s",
+				    pa->prefix, pname);
 				bsd.dev = pa->dev;
 				bsd.prefix = line;
 				bsd.verbose = pa->verbose;



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