From 205f3f4c9e26febea88cd566e30c036af4addd81 Mon Sep 17 00:00:00 2001 From: Covey Jorjet De Luna Date: Sat, 1 Aug 2026 20:47:29 +0800 Subject: [PATCH] Fix: -Wfloat-conversion error in print_number on MinGW isnan/isinf in MinGW-w64's math.h dispatch to float-typed helpers, so passing a double triggers -Wconversion/-Wfloat-conversion errors under -Werror. Replace the call with a pure C89 IEEE-754 check on double only: (d != d) detects NaN, and comparisons against DBL_MAX detect infinity. This avoids the platform isnan/isinf macros entirely, so it builds on older compilers (e.g. GCC 2.95) that lack __builtin_isnan/isinf and on other compilers that define __GNUC__. Also remove the now-unused ANSI C isnan/isinf fallback macros. --- cJSON.c | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-) diff --git a/cJSON.c b/cJSON.c index 88c2d95b3..959205ee9 100644 --- a/cJSON.c +++ b/cJSON.c @@ -69,14 +69,6 @@ #endif #define false ((cJSON_bool)0) -/* define isnan and isinf for ANSI C, if in C99 or above, isnan and isinf has been defined in math.h */ -#ifndef isinf -#define isinf(d) (isnan((d - d)) && !isnan(d)) -#endif -#ifndef isnan -#define isnan(d) (d != d) -#endif - #ifndef NAN #ifdef _WIN32 #define NAN sqrt(-1.0) @@ -609,7 +601,7 @@ static cJSON_bool print_number(const cJSON * const item, printbuffer * const out } /* This checks for NaN and Infinity */ - if (isnan(d) || isinf(d)) + if ((d != d) || (d > DBL_MAX) || (d < -DBL_MAX)) { length = sprintf((char*)number_buffer, "null"); }