From: Florian Forster Date: Mon, 3 Sep 2007 12:44:53 +0000 (+0200) Subject: sstrerror: Be even more cautios with the return value of `strerror_r'.. X-Git-Tag: collectd-4.0.8~11 X-Git-Url: https://git.verplant.org/?a=commitdiff_plain;h=3f5fc2f959affe8f2c40944aeed6c2bf75cf462c;p=collectd.git sstrerror: Be even more cautios with the return value of `strerror_r'.. I don't trust this GNU implementation one bit.. ;) --- diff --git a/src/common.c b/src/common.c index 7555b7ef..951bae30 100644 --- a/src/common.c +++ b/src/common.c @@ -82,13 +82,23 @@ char *sstrerror (int errnum, char *buf, size_t buflen) temp = strerror_r (errnum, buf, buflen); if (buf[0] == '\0') { - strncpy (buf, temp, buflen); + if ((temp != NULL) && (temp != buf) && (temp[0] != '\0')) + strncpy (buf, temp, buflen); + else + strncpy (buf, "strerror_r did not return " + "an error message", buflen); buf[buflen - 1] = '\0'; } } #else - strerror_r (errnum, buf, buflen); + if (strerror_r (errnum, buf, buflen) != 0) + { + snprintf (buf, buflen, "Error #%i; " + "Additionally, strerror_r failed.", + errnum); + } #endif /* STRERROR_R_CHAR_P */ + buf[buflen - 1] = '\0'; return (buf); } /* char *sstrerror */