summaryrefslogtreecommitdiffstats
path: root/common
diff options
context:
space:
mode:
authorSascha Hauer <s.hauer@pengutronix.de>2016-11-23 09:41:33 +0100
committerSascha Hauer <s.hauer@pengutronix.de>2017-01-10 08:27:33 +0100
commitc757c676428d70d854c3c7c637b8b7e7a8697043 (patch)
tree47e95747bfba6ad73e240230ea72309a2d85c6df /common
parent9fe05e5ebc13f215d96957ca18e00b71c0d926a4 (diff)
downloadbarebox-c757c676428d70d854c3c7c637b8b7e7a8697043.tar.gz
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>
Diffstat (limited to 'common')
-rw-r--r--common/boot.c2
-rw-r--r--common/menu.c12
2 files changed, 6 insertions, 8 deletions
diff --git a/common/boot.c b/common/boot.c
index 123b874..4306319 100644
--- a/common/boot.c
+++ b/common/boot.c
@@ -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;
diff --git a/common/menu.c b/common/menu.c
index 64df458..e757216 100644
--- a/common/menu.c
+++ b/common/menu.c
@@ -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);