fix: avoid generation of unvalid JSON in summary

This can happen when there are no available shared networks.  A division by
zero throws 'nan', which is non JSON-valid unless it's surrounded by double
quotes.
This commit is contained in:
luisδμ 2021-05-06 15:20:26 +02:00 committed by Sami Kerola
parent 5ed6e7688f
commit 7fc13c60e0
No known key found for this signature in database
GPG key ID: A9553245FDE9B739
2 changed files with 9 additions and 2 deletions

1
THANKS
View file

@ -51,3 +51,4 @@ Mathieu Morier
Jean Benoit
Belkacem Daheb
Björn Lässig
Luisδμ

View file

@ -611,9 +611,15 @@ static int output_json(struct conf_t *state)
fprintf(outfile, " \"touched\":%g,\n", state->shared_net_root->touched);
fprintf(outfile, " \"free\":%g,\n",
state->shared_net_root->available - state->shared_net_root->used);
fprintf(outfile, " \"percent\":%g,\n", oh.percent);
if (fpclassify(state->shared_net_root->available) == FP_ZERO)
fprintf(outfile, " \"percent\":\"%g\",\n", oh.percent);
else
fprintf(outfile, " \"percent\":%g,\n", oh.percent);
fprintf(outfile, " \"touch_count\":%g,\n", oh.tc);
fprintf(outfile, " \"touch_percent\":%g,\n", oh.tcp);
if (fpclassify(state->shared_net_root->available) == FP_ZERO)
fprintf(outfile, " \"touch_percent\":\"%g\",\n", oh.tcp);
else
fprintf(outfile, " \"touch_percent\":%g,\n", oh.tcp);
if (state->backups_found == 1) {
fprintf(outfile, " \"backup_count\":%g,\n",
state->shared_net_root->backups);