[Git][NTPsec/ntpsec][master] Fix JSON encoding in ntpfrob -j -c output

Matt Selsky gitlab at mg.gitlab.com
Wed Jul 25 22:02:40 UTC 2018


Matt Selsky pushed to branch master at NTPsec / ntpsec


Commits:
9a05bed4 by James Browning at 2018-07-25T20:47:48Z
Fix JSON encoding in ntpfrob -j -c output

Fixes Gitlab issue #494

- - - - -


1 changed file:

- ntpfrob/jitter.c


Changes:

=====================================
ntpfrob/jitter.c
=====================================
@@ -100,28 +100,26 @@ void jitter(const iomode mode)
 
 	if (mode == raw)
 	    exit(0);
-	
+
 	/*
 	 * Sort the gtod array and display deciles
 	 */
 	qsort(gtod, NBUF, sizeof(gtod[0]), doublecmp);
 	average = average / (NBUF - 2);
 	if (mode == json) {
-		fprintf(stdout, "{\"Average\":%13.9Lf,", average);
-		fprintf(stdout, "\"First rank\":[");
+		fprintf(stdout, "{\"Average\": %.9Lf, \"First rank\": [", average);
 		for (i = 0; i < NSAMPLES; i++) {
-		    fprintf(stdout, "%13.9f", gtod[i]);
+		    fprintf(stdout, "%.9f", gtod[i]);
 		    if (i < NSAMPLES - 1)
-			fputc(',', stdout);
-		    fputs("],", stdout);
+			fputs(", ", stdout);
 		}
-		fprintf(stdout, "\"Last rank\":");
+		fputs("], \"Last rank\": [", stdout);
 		for (i = NBUF - 12; i < NBUF - 2; i++) {
-		    fprintf(stdout, "%13.9f\n", gtod[i]);
-		    if (i < NSAMPLES - 1)
-			fputc(',', stdout);
-		    fputs("]}\n", stdout);
+		    fprintf(stdout, "%.9f", gtod[i]);
+		    if (i < NBUF - 3)
+			fputs(", ", stdout);
 		}
+		fputs("]}\n", stdout);
 	}
 	else if (mode != raw)
 	{



View it on GitLab: https://gitlab.com/NTPsec/ntpsec/commit/9a05bed4146502f0e9971fff3269d1518e6237d1

-- 
View it on GitLab: https://gitlab.com/NTPsec/ntpsec/commit/9a05bed4146502f0e9971fff3269d1518e6237d1
You're receiving this email because of your account on gitlab.com.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.ntpsec.org/pipermail/vc/attachments/20180725/7f6e4e1d/attachment.html>


More information about the vc mailing list