-
Notifications
You must be signed in to change notification settings - Fork 261
Open
Description
Line 754 in a2dd24f
| double result = strtod(ptr, &endptr); |
Currently the code uses strtod to parse floating point numbers from JSON arrays.
However, strtod respects the current process locale (LC_NUMERIC).
This causes incorrect behavior when the user’s locale is not "C":
- In French locale (
fr_FR.UTF-8),"0.1"is rejected because the expected separator is",". - JSON always requires a
.(dot) as the decimal separator. - As a result, JSON parsing will fail on systems where the locale is set to something other than
Coren_US.
Example:
setlocale(LC_NUMERIC, "fr_FR.UTF-8");
double x = strtod("0.1", NULL); // fails, does not parse
double y = strtod("0,1", NULL); // parses as 0.1Impact:
Parsing JSON arrays of floats will fail depending on the user’s locale, even though the input is valid JSON.
Possible fixes:
- Use
strtod_l/newlocalewith aClocale, for locale-independent parsing. - Or replace
strtodwith a locale-independent float parser (e.g. a custom implementation or a JSON parser library).
Expected behavior:
Parsing JSON should always interpret . as the decimal separator, regardless of the system locale.
Metadata
Metadata
Assignees
Labels
No labels