DaveGamble / cJSON

Ultralightweight JSON parser in ANSI C
MIT License
10.29k stars 3.15k forks source link

Problem with strtod() in parse_number() #452

Open justinbloomer opened 4 years ago

justinbloomer commented 4 years ago

Hi,

I am currently using source file cJSON.c for an embedded system that uses an old version of uClibc. The strtod() function is broken and I am unable to parse numbers. Would it be possible to reintroduce the old number parsing functionality before v1.3.0 that did not use strtod? Originally I did not have any issues when using the older version of cJSON, but this will not be possible to use on my current system. Another work around that I can think of is to use an strtod hook.

Best Regards Justin

ecrin4102 commented 4 years ago

To bypass this issue you can overwrite this function with your own.

mbratch commented 4 months ago

We are having the same issue. parse_number is a core function in cJSON, so I think it makes sense for it to be fixed in the library. It doesn't work on some CPU platforms. parse_number initially parses all numbers in the double realm, then casts it to the valueint. I think parse_number should parse integers as integers into valueint, and doubles as doubles parsed into valuedouble. When done, it can cast one to the other. I think that would get the best result.

For our work around, we also reverted to a much older version of cJSON.