]> wimlib.net Git - wimlib/blobdiff - src/util.c
wimlib_get_error_string(): Fix return value for some invalid numbers
[wimlib] / 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];
 }