summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorOndřej Lysoněk <olysonek@redhat.com>2019-05-05 11:17:45 +0200
committerOndřej Lysoněk <olysonek@redhat.com>2019-05-05 11:43:44 +0200
commit2c8cca3d6cd60121b401734c1a24cfec7daed4fc (patch)
treecdc4484f5a876f3e439a367b1db1a0a28a2ccad6
parent50f227dafe90efffb57eb483af25ae279218ad9e (diff)
downloadlm-sensors-git-2c8cca3d6cd60121b401734c1a24cfec7daed4fc.tar.gz
sensors: json: Do not print a stray comma
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 <olysonek@redhat.com>
-rw-r--r--prog/sensors/chips.c3
1 files changed, 2 insertions, 1 deletions
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 }");