analyze: fix formatting of timestamps with 0 µs
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Mon, 15 Jul 2019 17:11:16 +0000 (19:11 +0200)
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Mon, 15 Jul 2019 17:11:16 +0000 (19:11 +0200)
There is a rule that "%.0d" formats 0 as "". There is no such rule for
"%0d" and 0 :(. The output had an extra 0 if usec was 0.

src/analyze/analyze.c

index b7545c0..e9e66b3 100644 (file)
@@ -1859,11 +1859,13 @@ static int test_timestamp_one(const char *p) {
         if (r < 0)
                 return r;
 
-        r = table_add_cell_stringf(table, &cell, "@%"PRI_USEC"%s%0*"PRI_USEC"",
-                                   usec / USEC_PER_SEC,
-                                   usec % USEC_PER_SEC ? "." : "",
-                                   usec % USEC_PER_SEC ? 6 : 0,
-                                   usec % USEC_PER_SEC);
+        if (usec % USEC_PER_SEC == 0)
+                r = table_add_cell_stringf(table, &cell, "@%"PRI_USEC,
+                                           usec / USEC_PER_SEC);
+        else
+                r = table_add_cell_stringf(table, &cell, "@%"PRI_USEC".%06"PRI_USEC"",
+                                           usec / USEC_PER_SEC,
+                                           usec % USEC_PER_SEC);
         if (r < 0)
                 return r;