From e4d180562ca5e27d8a1ab6698479983b83d220fb Mon Sep 17 00:00:00 2001 From: Eric Biggers Date: Wed, 20 Aug 2014 23:41:27 -0500 Subject: [PATCH] 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. --- src/util.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) 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]; } -- 2.43.0