diff --git a/cJSON.c b/cJSON.c index 88c2d95b3..0c9684451 100644 --- a/cJSON.c +++ b/cJSON.c @@ -375,7 +375,12 @@ static cJSON_bool parse_number(cJSON * const item, parse_buffer * const input_bu } } - number = strtod((const char*)number_c_string, (char**)&after_end); + /* Use a char* temporary for strtod's end pointer. Passing + * (char**)&after_end would violate strict aliasing rules (UB), + * because after_end is an unsigned char*. */ + char *strtod_end = NULL; + number = strtod((const char*)number_c_string, &strtod_end); + after_end = (unsigned char*)strtod_end; if (number_c_string == after_end) { /* free the temporary buffer */