9
0
Fork 0

menu: sanitize menu_add_title

passing a string to menu_add_title() which then gets free by this
function is just plain ugly. Pass it a const char * which gets
duplicated in menu_add_title() when necessary.

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
This commit is contained in:
Sascha Hauer 2016-11-23 09:41:33 +01:00
parent 9fe05e5ebc
commit c757c67642
4 changed files with 8 additions and 10 deletions

View File

@ -147,7 +147,7 @@ static int do_menu_add(struct cmd_menu *cm)
if (!m->name)
goto free;
menu_add_title(m, strdup(cm->description));
menu_add_title(m, cm->description);
ret = menu_add(m);

View File

@ -44,7 +44,7 @@ struct bootentries *bootentries_alloc(void)
if (IS_ENABLED(CONFIG_MENU)) {
bootentries->menu = menu_alloc();
menu_add_title(bootentries->menu, basprintf("boot"));
menu_add_title(bootentries->menu, "boot");
}
return bootentries;

View File

@ -526,18 +526,17 @@ EXPORT_SYMBOL(menu_add_command_entry);
* @display: NULL or pointer to the string which will be freed in this function.
* If NULL or zero length string is provided, default title will be added.
*/
void menu_add_title(struct menu *m, char *display)
void menu_add_title(struct menu *m, const char *display)
{
char *tmp, *src, *dst;
int lines = 1;
int i;
if (!display || !strlen(display)) {
free(display);
display = xasprintf("Menu : %s", m->name ? m->name : "");
}
if (!display || !strlen(display))
src = dst = tmp = xasprintf("Menu : %s", m->name ? m->name : "");
else
src = dst = tmp = xstrdup(display);
src = dst = tmp = xstrdup(display);
/* Count lines and separate single string into multiple strings */
while (*src) {
if (*src == '\\') {
@ -575,6 +574,5 @@ void menu_add_title(struct menu *m, char *display)
}
free(tmp);
free(display);
}
EXPORT_SYMBOL(menu_add_title);

View File

@ -91,7 +91,7 @@ int menu_set_selected_entry(struct menu *m, struct menu_entry* me);
int menu_set_selected(struct menu *m, int num);
int menu_set_auto_select(struct menu *m, int delay);
struct menu* menu_get_menus(void);
void menu_add_title(struct menu *m, char *display);
void menu_add_title(struct menu *m, const char *display);
/*
* menu entry functions