https://gcc.gnu.org/g:ee4cc961ce399f2f3ac92fd711551677d61771da

commit r15-2451-gee4cc961ce399f2f3ac92fd711551677d61771da
Author: Jonathan Wakely <jwak...@redhat.com>
Date:   Wed Jul 31 13:56:14 2024 +0100

    libstdc++: Handle strerror returning null
    
    The linux man page for strerror says that some systems return NULL for
    an unknown error number. That violates the C and POSIX standards, but we
    can esily handle it to avoid a segfault.
    
    libstdc++-v3/ChangeLog:
    
            * src/c++11/system_error.cc (strerror_string): Handle
            non-conforming NULL return from strerror.

Diff:
---
 libstdc++-v3/src/c++11/system_error.cc | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/libstdc++-v3/src/c++11/system_error.cc 
b/libstdc++-v3/src/c++11/system_error.cc
index d01451ba1ef6..38bc04461101 100644
--- a/libstdc++-v3/src/c++11/system_error.cc
+++ b/libstdc++-v3/src/c++11/system_error.cc
@@ -110,7 +110,11 @@ namespace
 #else
   string strerror_string(int err)
   {
-    return strerror(err); // XXX Not thread-safe.
+    auto str = strerror(err); // XXX Not thread-safe.
+    if (str) [[__likely__]]
+      return str;
+    // strerror should not return NULL, but some implementations do.
+    return "Unknown error";
   }
 #endif

Reply via email to