This allows access to an element after the end of the array. Fix it.
Reported-by: Coverity (CID: 173279)
Signed-off-by: Simon Glass <sjg@chromium.org>
const char *log_get_cat_name(enum log_category_t cat)
{
- if (cat > LOGC_COUNT)
- return "invalid";
+ const char *name;
+
+ if (cat < 0 || cat >= LOGC_COUNT)
+ return "<invalid>";
if (cat >= LOGC_NONE)
return log_cat_name[cat - LOGC_NONE];
- return uclass_get_name((enum uclass_id)cat);
+ name = uclass_get_name((enum uclass_id)cat);
+
+ return name ? name : "<missing>";
}
enum log_category_t log_get_cat_by_name(const char *name)
* log_get_cat_name() - Get the name of a category
*
* @cat: Category to look up
- * @return category name (which may be a uclass driver name)
+ * @return category name (which may be a uclass driver name) if found, or
+ * "<invalid>" if invalid, or "<missing>" if not found
*/
const char *log_get_cat_name(enum log_category_t cat);