[libcxx] r272640 - Fix error checking for strerror_r implementations that return the error code.
Eric Fiselier via cfe-commits
cfe-commits at lists.llvm.org
Mon Jun 13 23:03:20 PDT 2016
Author: ericwf
Date: Tue Jun 14 01:03:20 2016
New Revision: 272640
URL: http://llvm.org/viewvc/llvm-project?rev=272640&view=rev
Log:
Fix error checking for strerror_r implementations that return the error code.
Modified:
libcxx/trunk/src/system_error.cpp
Modified: libcxx/trunk/src/system_error.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/src/system_error.cpp?rev=272640&r1=272639&r2=272640&view=diff
==============================================================================
--- libcxx/trunk/src/system_error.cpp (original)
+++ libcxx/trunk/src/system_error.cpp Tue Jun 14 01:03:20 2016
@@ -70,8 +70,10 @@ string do_strerror_r(int ev) {
string do_strerror_r(int ev) {
char buffer[strerror_buff_size];
const int old_errno = errno;
- if (::strerror_r(ev, buffer, strerror_buff_size) == -1) {
- const int new_errno = errno;
+ if ((int ret = ::strerror_r(ev, buffer, strerror_buff_size)) != 0) {
+ // If `ret == -1` then the error is specified using `errno`, otherwise
+ // `ret` represents the error.
+ const int new_errno = ret == -1 ? errno : ret;
errno = old_errno;
if (new_errno == EINVAL) {
std::snprintf(buffer, strerror_buff_size, "Unknown error %d", ev);
More information about the cfe-commits
mailing list