DaveGamble / cJSON

Ultralightweight JSON parser in ANSI C
MIT License
10.63k stars 3.2k forks source link

Treat Integers and floating point numbers as totally separated types. Doing int-double or double-double strict comparisons is wrong #694

Open cr1st1p opened 2 years ago

cr1st1p commented 2 years ago

Issue at hand: a simple json with 1 string field and 1 integer field ("cJSON_addNumber") - fails to be print_unformatted. I saw https://github.com/DaveGamble/cJSON/issues/585 - and someone had a similar problem on my platform - esp8266 RTOS SDK). And the reason of failure is due to some missing feature on my platform for sprintf'ing floating point numbers.

But... a) what I want to use is NOT a floating point number and I should NOT have to compile in some additional functionality for floating numbers b) the fix for the mentioned bug - https://github.com/DaveGamble/cJSON/pull/630/files is wrong. You should never strictly compare floating point numbers (the integer value is most probably converted first to a floating number https://www.cs.technion.ac.il/users/yechiel/c++-faq/floating-point-arith.html Please check to see if you are having other such strict comparisons in your code.

Please treat integer numbers completely separate from floating ones.

abzmr commented 2 years ago

Again plugging my own PR: #690 has integers as first-class citizens.