From: Eric Biggers Date: Thu, 21 Aug 2014 04:41:27 +0000 (-0500) Subject: wimlib_get_error_string(): Fix return value for some invalid numbers X-Git-Tag: v1.7.2~55 X-Git-Url: https://wimlib.net/git/?p=wimlib;a=commitdiff_plain;h=e4d180562ca5e27d8a1ab6698479983b83d220fb wimlib_get_error_string(): Fix return value for some invalid numbers The function was returning NULL for unknown error codes in the range of the array. But it should return "Unknown error" for such codes. --- diff --git a/src/util.c b/src/util.c index 508f6f8e..33c611c8 100644 --- a/src/util.c +++ b/src/util.c @@ -385,12 +385,14 @@ static const tchar *error_strings[] = { /* API function documented in wimlib.h */ WIMLIBAPI const tchar * -wimlib_get_error_string(enum wimlib_error_code code) +wimlib_get_error_string(enum wimlib_error_code _code) { - if ((unsigned int)code >= ARRAY_LEN(error_strings)) + unsigned int code = (unsigned int)_code; + + if (code >= ARRAY_LEN(error_strings) || error_strings[code] == NULL) return T("Unknown error"); - return error_strings[(unsigned int)code]; + return error_strings[code]; }