From f0fd292ccb2ed6bbaf5cffcdb79a465e11313dce Mon Sep 17 00:00:00 2001 From: Esteve Fernandez Date: Thu, 3 Dec 2015 16:30:34 -0800 Subject: [PATCH] Avoid unused return value warning --- rclcpp/src/rclcpp/utilities.cpp | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/rclcpp/src/rclcpp/utilities.cpp b/rclcpp/src/rclcpp/utilities.cpp index 4ae1b55..bc0b365 100644 --- a/rclcpp/src/rclcpp/utilities.cpp +++ b/rclcpp/src/rclcpp/utilities.cpp @@ -117,7 +117,18 @@ rclcpp::utilities::init(int argc, char * argv[]) // NOLINTNEXTLINE(runtime/arrays) char error_string[error_length]; #ifndef _WIN32 - strerror_r(errno, error_string, error_length); +#ifdef _GNU_SOURCE + char * msg = strerror_r(errno, error_string, error_length); + if (msg != error_string) { + strncpy(error_string, msg, error_length); + msg[error_length - 1] = '\0'; + } +#else + int error_status = strerror_r(errno, error_string, error_length); + if (error_status != 0) { + throw std::runtime_error("Failed to get error string for errno: " + std::to_string(errno)); + } +#endif #else strerror_s(error_string, error_length, errno); #endif