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.
This commit is contained in:
Jonathan Wakely 2024-07-31 13:56:14 +01:00 committed by Jonathan Wakely
parent 5dd1f0d69f
commit ee4cc961ce
No known key found for this signature in database

View File

@ -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