From: Guus Sliepen Date: Wed, 30 Jul 2014 09:05:08 +0000 (+0200) Subject: Make sure meshlink_strerror() always returns a valid pointer to a string. X-Git-Url: https://git.meshlink.io/?a=commitdiff_plain;h=b91fe5598024bbda9f22773c404e3f4d98d53159;p=meshlink Make sure meshlink_strerror() always returns a valid pointer to a string. --- diff --git a/src/meshlink.c b/src/meshlink.c index 80404370..f4e213c5 100644 --- a/src/meshlink.c +++ b/src/meshlink.c @@ -630,6 +630,8 @@ static const char *errstr[] = { }; const char *meshlink_strerror(meshlink_errno_t err) { + if(err < 0 || err >= sizeof errstr / sizeof *errstr) + return "Invalid error code"; return errstr[err]; } diff --git a/src/meshlink.h b/src/meshlink.h index 39f278d2..7fd71fe8 100644 --- a/src/meshlink.h +++ b/src/meshlink.h @@ -72,6 +72,7 @@ struct meshlink_channel { * @param err An error code returned by MeshLink. * * @return A pointer to a string containing the description of the error code. + * This function will always return a valid pointer, even if an invalid error code has been passed. */ extern const char *meshlink_strerror(meshlink_errno_t err);