cJSON icon indicating copy to clipboard operation
cJSON copied to clipboard

Problem with strtod() in parse_number()

Open justinbloomer opened this issue 5 years ago • 2 comments

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

justinbloomer avatar Mar 25 '20 12:03 justinbloomer

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

ecrin4102 avatar Apr 16 '20 16:04 ecrin4102

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.

mbratch avatar Feb 22 '24 20:02 mbratch