mirror of
git://git.code.sf.net/p/dhcpd-pools/code
synced 2025-12-14 14:57:00 +00:00
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:
parent
5ed6e7688f
commit
7fc13c60e0
2 changed files with 9 additions and 2 deletions
1
THANKS
1
THANKS
|
|
@ -51,3 +51,4 @@ Mathieu Morier
|
|||
Jean Benoit
|
||||
Belkacem Daheb
|
||||
Björn Lässig
|
||||
Luisδμ
|
||||
|
|
|
|||
10
src/output.c
10
src/output.c
|
|
@ -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);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue