File tree Expand file tree Collapse file tree 1 file changed +10
-4
lines changed
Expand file tree Collapse file tree 1 file changed +10
-4
lines changed Original file line number Diff line number Diff line change 4242#include "debug.h"
4343#include "module.h"
4444#include "utils/list.h"
45+ #include "utils/macros.h" // for ARR_COUNT, to_fourcc
4546
4647#define MOD_NAME "[module] "
4748#define MODULE_MAGIC to_fourcc('M', 'O', 'D', ' ')
@@ -156,7 +157,7 @@ void module_done(struct module *module_data)
156157 free (module_priv );
157158}
158159
159- static const char * module_class_name_pairs [] = {
160+ static const char * const module_class_name_pairs [] = {
160161 [MODULE_CLASS_ROOT ] = "root" ,
161162 [MODULE_CLASS_PORT ] = "port" ,
162163 [MODULE_CLASS_COMPRESS ] = "compress" ,
@@ -176,10 +177,15 @@ static const char *module_class_name_pairs[] = {
176177
177178const char * module_class_name (enum module_class cls )
178179{
179- if ((unsigned int ) cls < sizeof (module_class_name_pairs )/sizeof (const char * ))
180- return module_class_name_pairs [cls ];
181- else
180+ if ((unsigned int ) cls >= ARR_COUNT (module_class_name_pairs )) {
181+ MSG (ERROR , "No name for module class %d!\n" , (int ) cls );
182182 return NULL ;
183+ }
184+ const char * name = module_class_name_pairs [cls ];
185+ if (name == NULL ) { // eg. for MODULE_CLASS_NONE
186+ MSG (ERROR , "Undefined name for module class %d!\n" , (int ) cls );
187+ }
188+ return name ;
183189}
184190
185191void
You can’t perform that action at this time.
0 commit comments