diff options
author | Jonathan Wakely <jwakely@redhat.com> | 2024-07-31 13:56:14 +0100 |
---|---|---|
committer | Jonathan Wakely <redi@gcc.gnu.org> | 2024-07-31 17:07:11 +0100 |
commit | ee4cc961ce399f2f3ac92fd711551677d61771da (patch) | |
tree | f02cbab56ef7f43647f64da5651fd08e22e4300d | |
parent | 5dd1f0d69f51dc6b290977503dcfb7734948e841 (diff) | |
download | gcc-ee4cc961ce399f2f3ac92fd711551677d61771da.zip gcc-ee4cc961ce399f2f3ac92fd711551677d61771da.tar.gz gcc-ee4cc961ce399f2f3ac92fd711551677d61771da.tar.bz2 |
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.
-rw-r--r-- | libstdc++-v3/src/c++11/system_error.cc | 6 |
1 files changed, 5 insertions, 1 deletions
diff --git a/libstdc++-v3/src/c++11/system_error.cc b/libstdc++-v3/src/c++11/system_error.cc index d01451b..38bc044 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 |