[libc] [llvm] [libc] Fix undefined behavior for nan functions. (PR #106468)

via llvm-commits llvm-commits at lists.llvm.org
Thu Sep 5 11:36:24 PDT 2024


================
@@ -1208,6 +1210,15 @@ template <class T> LIBC_INLINE StrToNumResult<T> strtonan(const char *arg) {
   using FPBits = typename fputil::FPBits<T>;
   using StorageType = typename FPBits::StorageType;
 
+#ifndef LIBC_HAS_SANITIZER
+  if (LIBC_UNLIKELY(arg == nullptr)) {
+    // Use volatile to prevent undefined behavior of dereferencing nullptr.
----------------
lntue wrote:

I refactor it to a generic macro in `__support/macros/null_check.h`

https://github.com/llvm/llvm-project/pull/106468


More information about the llvm-commits mailing list