From 2c8cca3d6cd60121b401734c1a24cfec7daed4fc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ond=C5=99ej=20Lyson=C4=9Bk?= Date: Sun, 5 May 2019 11:17:45 +0200 Subject: [PATCH] sensors: json: Do not print a stray comma MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Previously, if an error happened when reading the value of a subfeature, subCnt would get incremented and a stray comma would get printed in the following iteration, even though nothing was printed in the previous iteration. This would produce a syntactically incorrect JSON. This is based on a patch from the su8 user on GitHub. Signed-off-by: Ondřej Lysoněk --- prog/sensors/chips.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/prog/sensors/chips.c b/prog/sensors/chips.c index c293ae44..99426a4b 100644 --- a/prog/sensors/chips.c +++ b/prog/sensors/chips.c @@ -101,12 +101,13 @@ void print_chip_json(const sensors_chip_name *name) if (subCnt > 0) printf(",\n"); printf(" \"%s\": %.3f", sub->name, val); + subCnt++; } } else { printf("(%s)", label); + subCnt++; } - subCnt++; } free(label); printf("\n }");