Skip to content

Fix: avoid strict-aliasing violation in parse_number - #1131

Open
YikunWei-dev wants to merge 1 commit into
DaveGamble:masterfrom
YikunWei-dev:fix/parse-number-strict-aliasing
Open

YikunWei-dev wants to merge 1 commit into
DaveGamble:masterfrom
YikunWei-dev:fix/parse-number-strict-aliasing

Conversation

@YikunWei-dev

Copy link
Copy Markdown

In parse_number, strtod's end pointer was obtained by casting (unsigned char **) to (char *) and writing through it, which is a strict-aliasing violation (undefined behavior). Use an intermediate char variable and assign it back to after_end instead.

No behavior change; verified cJSON.c still compiles and the existing parse_number tests pass.

In parse_number, strtod's end pointer was obtained by casting
(unsigned char **) to (char **) and writing through it, which is a
strict-aliasing violation (undefined behavior). Use an intermediate
char* variable and assign it back to after_end instead.

No behavior change; verified cJSON.c still compiles and the existing
parse_number tests pass.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant