]> wimlib.net Git - wimlib/commitdiff
wimlib_get_error_string(): Fix return value for some invalid numbers
authorEric Biggers <ebiggers3@gmail.com>
Thu, 21 Aug 2014 04:41:27 +0000 (23:41 -0500)
committerEric Biggers <ebiggers3@gmail.com>
Thu, 21 Aug 2014 04:45:25 +0000 (23:45 -0500)
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

index 508f6f8ee357e53c523a781144d3fa9c716fd470..33c611c811558337bcd6d1b2914ba72a1be97cca 100644 (file)
@@ -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];
 }