From 983e13c611eaebed3b715507a4954bc753d34627 Mon Sep 17 00:00:00 2001 From: Yunlong Date: Sat, 28 Mar 2026 22:13:15 +0800 Subject: [PATCH] Add nan and inf flot number check to avoid integer overflow --- cJSON.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/cJSON.c b/cJSON.c index 88c2d95b..bba49acc 100644 --- a/cJSON.c +++ b/cJSON.c @@ -2511,7 +2511,11 @@ CJSON_PUBLIC(cJSON *) cJSON_CreateNumber(double num) item->valuedouble = num; /* use saturation in case of overflow */ - if (num >= INT_MAX) + if (isnan(num) || isinf(num)) + { + item->valueint = 0; + } + else if (num >= INT_MAX) { item->valueint = INT_MAX; }