PROTON-1029: do not crash if strerror fails
Project: http://git-wip-us.apache.org/repos/asf/qpid-proton/repo Commit: http://git-wip-us.apache.org/repos/asf/qpid-proton/commit/7c132f35 Tree: http://git-wip-us.apache.org/repos/asf/qpid-proton/tree/7c132f35 Diff: http://git-wip-us.apache.org/repos/asf/qpid-proton/diff/7c132f35 Branch: refs/heads/go1 Commit: 7c132f35392448d2623a01915ea9ce6303453162 Parents: 55abbc8 Author: Ken Giusti <[email protected]> Authored: Fri Oct 23 16:50:59 2015 -0400 Committer: Ken Giusti <[email protected]> Committed: Wed Oct 28 08:48:46 2015 -0400 ---------------------------------------------------------------------- proton-c/src/platform.c | 23 +++++++++-------------- 1 file changed, 9 insertions(+), 14 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/7c132f35/proton-c/src/platform.c ---------------------------------------------------------------------- diff --git a/proton-c/src/platform.c b/proton-c/src/platform.c index 5470c5a..3a8cade 100644 --- a/proton-c/src/platform.c +++ b/proton-c/src/platform.c @@ -65,25 +65,20 @@ pn_timestamp_t pn_i_now(void) } #endif -#ifdef USE_STRERROR_R #include <string.h> -static void pn_i_strerror(int errnum, char *buf, size_t buflen) { - if (strerror_r(errnum, buf, buflen) != 0) pni_fatal("strerror_r() failed\n"); -} +#include <stdio.h> +static void pn_i_strerror(int errnum, char *buf, size_t buflen) +{ + // PROTON-1029 provide a simple default in case strerror fails + snprintf(buf, buflen, "errno: %d", errnum); +#ifdef USE_STRERROR_R + strerror_r(errnum, buf, buflen); #elif USE_STRERROR_S -#include <string.h> -static void pn_i_strerror(int errnum, char *buf, size_t buflen) { - if (strerror_s(buf, buflen, errnum) != 0) pni_fatal("strerror_s() failed\n"); -} + strerror_s(buf, buflen, errnum); #elif USE_OLD_STRERROR -// This is thread safe on some platforms, and the only option on others -#include <string.h> -static void pn_i_strerror(int errnum, char *buf, size_t buflen) { strncpy(buf, strerror(errnum), buflen); -} -#else -#error "Don't know a safe strerror equivalent for this platform" #endif +} int pn_i_error_from_errno(pn_error_t *error, const char *msg) { --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
