summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSascha Hauer <s.hauer@pengutronix.de>2010-08-21 17:02:09 +0200
committerSascha Hauer <s.hauer@pengutronix.de>2010-08-30 20:57:20 +0200
commitf371f04df2d333fe3c3bd8968623fabde9d1f088 (patch)
treecd5afea84b50876c5df7d5f0538fdea001935a9a
parent86086c5faafb8ac8d00b4edbbf51de5fbe03b6b9 (diff)
downloadbarebox-f371f04df2d333fe3c3bd8968623fabde9d1f088.tar.gz
barebox-f371f04df2d333fe3c3bd8968623fabde9d1f088.tar.xz
menu: Use strdup instead of malloc/strncpy
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
-rw-r--r--commands/menu.c31
1 files changed, 5 insertions, 26 deletions
diff --git a/commands/menu.c b/commands/menu.c
index 237de9fc17..39f106b5ab 100644
--- a/commands/menu.c
+++ b/commands/menu.c
@@ -67,7 +67,6 @@ static int do_menu_entry_add(struct cmd_menu *cm)
{
struct menu_entry *me;
struct menu *m, *sm;
- int len;
int ret = -ENOMEM;
if (!cm->menu || (!cm->command && !cm->submenu) || !cm->description)
@@ -99,25 +98,15 @@ static int do_menu_entry_add(struct cmd_menu *cm)
} else {
me->action = menu_action_run;
- len = strlen(cm->command) + 1;
-
- me->priv = calloc(len, sizeof(char));
-
+ me->priv = strdup(cm->command);
if (!me->priv)
goto free;
-
- strncpy(me->priv, cm->command, len);
}
- len = strlen(cm->description) + 1;
-
- me->display = calloc(len, sizeof(char));;
-
- if (!m->display)
+ me->display = strdup(cm->description);
+ if (!me->display)
goto free;
- strncpy(me->display, cm->description, len);
-
ret = menu_add_entry(m, me);
if (ret)
@@ -175,7 +164,6 @@ static int do_menu_entry_remove(struct cmd_menu *cm)
static int do_menu_add(struct cmd_menu *cm)
{
struct menu *m;
- int len = 0;
int ret = -ENOMEM;
if (!cm->menu || !cm->description)
@@ -186,23 +174,14 @@ static int do_menu_add(struct cmd_menu *cm)
if (!m)
goto free;
- len = strlen(cm->menu) + 1;
-
- m->name = calloc(len, sizeof(char));;
+ m->name = strdup(cm->menu);
if (!m->name)
goto free;
- strncpy(m->name, cm->menu, len);
-
- len = strlen(cm->description) + 1;
-
- m->display = calloc(len, sizeof(char));;
-
+ m->display = strdup(cm->description);
if (!m->display)
goto free;
- strncpy(m->display, cm->description, len);
-
ret = menu_add(m);
if (ret)