[PATCH 2/9] menu: Use strdup instead of malloc/strncpy
Sascha Hauer
s.hauer at pengutronix.de
Mon Aug 23 02:24:06 EDT 2010
Signed-off-by: Sascha Hauer <s.hauer at pengutronix.de>
---
commands/menu.c | 31 +++++--------------------------
1 files changed, 5 insertions(+), 26 deletions(-)
diff --git a/commands/menu.c b/commands/menu.c
index 237de9f..39f106b 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)
--
1.7.1
More information about the barebox
mailing list