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;
_______________________________________________
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