This is an automated email from the ASF dual-hosted git repository.

apitrou pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/arrow.git


The following commit(s) were added to refs/heads/main by this push:
     new daa2efad5b GH-41154: [C++] Fix Valgrind error in string-to-float16 
conversion (#41155)
daa2efad5b is described below

commit daa2efad5bae144072a9c46f6a8978dc6d7363f9
Author: Antoine Pitrou <[email protected]>
AuthorDate: Thu Apr 11 19:44:47 2024 +0200

    GH-41154: [C++] Fix Valgrind error in string-to-float16 conversion (#41155)
    
    ### Rationale for this change
    
    Only do the final conversion to float16 on success, to avoid conditional 
jump on uninitialized values.
    
    Note: this is a benign error. But we want our Valgrind CI job to be as 
successful as possible.
    
    ### Are these changes tested?
    
    Yes, on CI.
    
    ### Are there any user-facing changes?
    
    No.
    * GitHub Issue: #41154
    
    Authored-by: Antoine Pitrou <[email protected]>
    Signed-off-by: Antoine Pitrou <[email protected]>
---
 cpp/src/arrow/util/value_parsing.cc | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/cpp/src/arrow/util/value_parsing.cc 
b/cpp/src/arrow/util/value_parsing.cc
index e84aac995e..8cecc6365a 100644
--- a/cpp/src/arrow/util/value_parsing.cc
+++ b/cpp/src/arrow/util/value_parsing.cc
@@ -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;
 }
 
 // ----------------------------------------------------------------------

Reply via email to