From 741e30cff661968f876dd56714489c7c89e857bd Mon Sep 17 00:00:00 2001 From: Tanel Dettenborn Date: Sun, 30 Jun 2024 01:08:06 +0300 Subject: [PATCH] Enforce sscanf-function return value check at print_number-function --- cJSON.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/cJSON.c b/cJSON.c index cac1164b..0a363b0e 100644 --- a/cJSON.c +++ b/cJSON.c @@ -580,7 +580,12 @@ static cJSON_bool print_number(const cJSON * const item, printbuffer * const out length = sprintf((char*)number_buffer, "%1.15g", d); /* Check whether the original double can be recovered */ - if ((sscanf((char*)number_buffer, "%lg", &test) != 1) || !compare_double((double)test, d)) + if (sscanf((char*)number_buffer, "%lg", &test) != 1) + { + return false; + } + + if (!compare_double((double)test, d)) { /* If not, print with 17 decimal places of precision */ length = sprintf((char*)number_buffer, "%1.17g", d);