2
0
mirror of https://github.com/lm-sensors/lm-sensors synced 2025-08-30 05:48:07 +00:00

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>
This commit is contained in:
Ondřej Lysoněk 2019-05-05 11:17:45 +02:00
parent 50f227dafe
commit 2c8cca3d6c

View File

@ -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 }");