From eefad54be79b44cb32fc82ca601ac0faa2106302 Mon Sep 17 00:00:00 2001 From: Theo Arends <11044339+arendst@users.noreply.github.com> Date: Thu, 25 Oct 2018 14:03:34 +0200 Subject: [PATCH] Fix invalid JSON Fix invalid JSON floating point result from nan (Not a Number) and inf (Infinity) into null (#4147) --- sonoff/_changelog.ino | 2 +- sonoff/support.ino | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/sonoff/_changelog.ino b/sonoff/_changelog.ino index 0c13b2ef7..21ceff6b5 100644 --- a/sonoff/_changelog.ino +++ b/sonoff/_changelog.ino @@ -1,6 +1,6 @@ /* 6.2.1.19 20181023 * Fix header file execution order by renaming user_config.h to my_user_config.h - * Fix invalid JSON floating point result from nan into null (#4147) + * Fix invalid JSON floating point result from nan (Not a Number) and inf (Infinity) into null (#4147) * * 6.2.1.18 20181019 * Add more API callbacks and document API.md diff --git a/sonoff/support.ino b/sonoff/support.ino index 1e960bb16..83c154834 100644 --- a/sonoff/support.ino +++ b/sonoff/support.ino @@ -196,7 +196,7 @@ int TextToInt(char *str) char* dtostrfd(double number, unsigned char prec, char *s) { - if (isnan(number)) { + if ((isnan(number)) || (isinf(number))) { // Fix for JSON output (https://stackoverflow.com/questions/1423081/json-left-out-infinity-and-nan-json-status-in-ecmascript) strcpy(s, "null"); return s; } else {