diff --git a/srcs/libs/misc/err.c b/srcs/libs/misc/err.c index e7bba06..143d137 100644 --- a/srcs/libs/misc/err.c +++ b/srcs/libs/misc/err.c @@ -2,6 +2,7 @@ // Created by xajhuang on 2022/12/5. // #include +#include "misc.h" #define MAX_DESC_LENGTH (256) #define GENERATE_STRING(STRING, no, desc) {#STRING, desc}, @@ -11,13 +12,22 @@ static const char *g_enumStrVal[][MAX_DESC_LENGTH] = { }; const char *getErrorEnumNameString(int errCode) { + if (errCode >= ARRAY_SIZE(g_enumStrVal) || errCode < 0) { + return g_enumStrVal[ARRAY_SIZE(g_enumStrVal) - 1][0]; + } return g_enumStrVal[errCode][0]; } const char *getErrorEnumDesc(int errCode) { + if (errCode >= ARRAY_SIZE(g_enumStrVal) || errCode < 0) { + return g_enumStrVal[ARRAY_SIZE(g_enumStrVal) - 1][0]; + } return g_enumStrVal[errCode][0]; } const char *getErrorEnumDescripty(int errCode) { + if (errCode >= ARRAY_SIZE(g_enumStrVal) || errCode < 0) { + return g_enumStrVal[ARRAY_SIZE(g_enumStrVal) - 1][1]; + } return g_enumStrVal[errCode][1]; }