Skip to content

Commit

Permalink
apacheGH-41154: [C++] Fix Valgrind error in string-to-float16 conversion
Browse files Browse the repository at this point in the history
Only do the final conversion to float16 on success, to avoid conditional jump on uninitialized values.
  • Loading branch information
pitrou committed Apr 11, 2024
1 parent 6269317 commit 14d89bf
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions cpp/src/arrow/util/value_parsing.cc
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,11 @@ bool StringToFloat(const char* s, size_t length, char decimal_point, uint16_t* o
float temp_out;
const auto res =
::arrow_vendored::fast_float::from_chars_advanced(s, s + length, temp_out, options);
*out = Float16::FromFloat(temp_out).bits();
return res.ec == std::errc() && res.ptr == s + length;
const bool ok = res.ec == std::errc() && res.ptr == s + length;
if (ok) {
*out = Float16::FromFloat(temp_out).bits();
}
return ok;
}

// ----------------------------------------------------------------------
Expand Down

0 comments on commit 14d89bf

Please sign in to comment.