commit a2f60e89419154ea02c7b28558abcfb3c2fc0955
parent 0e4d01f69081f5d9263cdf0a02a9bfb94f301ebb
Author: Evgeny Grin (Karlson2k) <k2k@drgrin.dev>
Date: Sun, 21 Dec 2025 17:51:59 +0100
mhd_enum_to_str.c: return string "invalid" for zero values, which is part of the enums
Diffstat:
1 file changed, 13 insertions(+), 8 deletions(-)
diff --git a/src/mhd2/mhd_enum_to_str.c b/src/mhd2/mhd_enum_to_str.c
@@ -45,6 +45,7 @@
#include "mhd_sys_options.h"
+#include "mhd_arr_num_elems.h"
#include "mhd_str_macros.h"
#include "sys_null_macro.h"
@@ -61,10 +62,12 @@ MHD_protocol_version_to_string (enum MHD_HTTP_ProtocolVersion pv)
mhd_MSTR_INIT ("HTTP/3")
};
- if ( (pv > 0) &&
- ((unsigned int) pv < sizeof (results) / sizeof(results[0])) )
- return &results[pv];
- return NULL;
+ if (0 > pv)
+ return NULL;
+ if (mhd_ARR_NUM_ELEMS (results) >= (unsigned int) pv)
+ return NULL;
+
+ return results + (unsigned int) pv;
}
@@ -84,8 +87,10 @@ MHD_http_method_to_string (enum MHD_HTTP_Method method)
mhd_MSTR_INIT ("*")
};
- if ( (method > 0) &&
- ((unsigned int) method < sizeof (results) / sizeof(results[0])) )
- return &results[method];
- return NULL;
+ if (0 > method)
+ return NULL;
+ if (mhd_ARR_NUM_ELEMS (results) >= (unsigned int) method)
+ return NULL;
+
+ return results + (unsigned int) method;
}