diff options
author | Eric Fiselier <eric@efcs.ca> | 2016-06-14 06:03:20 +0000 |
---|---|---|
committer | Eric Fiselier <eric@efcs.ca> | 2016-06-14 06:03:20 +0000 |
commit | 79e0574db084843bcc38c87a441fb8035cdf6cf2 (patch) | |
tree | 05ad537010a700b0c652693ff1ea9357073c6cc4 /libcxx/src/system_error.cpp | |
parent | d046d5422addf47472087f258a871285caf705f4 (diff) | |
download | llvm-79e0574db084843bcc38c87a441fb8035cdf6cf2.zip llvm-79e0574db084843bcc38c87a441fb8035cdf6cf2.tar.gz llvm-79e0574db084843bcc38c87a441fb8035cdf6cf2.tar.bz2 |
Fix error checking for strerror_r implementations that return the error code.
llvm-svn: 272640
Diffstat (limited to 'libcxx/src/system_error.cpp')
-rw-r--r-- | libcxx/src/system_error.cpp | 6 |
1 files changed, 4 insertions, 2 deletions
diff --git a/libcxx/src/system_error.cpp b/libcxx/src/system_error.cpp index 748b5f7..d7115fc 100644 --- a/libcxx/src/system_error.cpp +++ b/libcxx/src/system_error.cpp @@ -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); |