]> www.infradead.org Git - users/sagi/nvme-cli.git/commitdiff
Fix right trim() in JSON output
authorAaron Miller <aaronmiller@fb.com>
Fri, 9 Dec 2016 23:38:35 +0000 (15:38 -0800)
committerAaron Miller <aaronmiller@fb.com>
Fri, 9 Dec 2016 23:54:00 +0000 (15:54 -0800)
Was always trimming from the end of the format buffer, not the end of
the snprintf output. Also need to remove the initial decrement as
snprintf will leave fmt_sz pointing at the terminating NUL.

nvme-print.c

index c85e4860af1b9f91fcad7ef3bc8fe8807344d9ba..620b421e8372ac7bc81999c4a3c88636ada6856f 100644 (file)
@@ -63,14 +63,15 @@ void d_raw(unsigned char *buf, unsigned len)
 static void format(char *formatter, size_t fmt_sz, char *tofmt, size_t tofmtsz)
 {
 
-       snprintf(formatter,fmt_sz, "%-*.*s",
+       fmt_sz = snprintf(formatter,fmt_sz, "%-*.*s",
                 (int)tofmtsz, (int)tofmtsz, tofmt);
        /* trim() the obnoxious trailing white lines */
-       while (--fmt_sz) {
+       while (fmt_sz) {
                if (formatter[fmt_sz - 1] != ' ' && formatter[fmt_sz - 1] != '\0') {
                        formatter[fmt_sz] = '\0';
                        break;
                }
+               fmt_sz--;
        }
 }