mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Sascha Hauer <s.hauer@pengutronix.de>
To: barebox@lists.infradead.org
Subject: [PATCH 2/9] menu: Use strdup instead of malloc/strncpy
Date: Mon, 23 Aug 2010 08:24:06 +0200	[thread overview]
Message-ID: <1282544653-11508-3-git-send-email-s.hauer@pengutronix.de> (raw)
In-Reply-To: <1282544653-11508-1-git-send-email-s.hauer@pengutronix.de>

Signed-off-by: Sascha Hauer <s.hauer@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


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

  parent reply	other threads:[~2010-08-23  6:24 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-08-23  6:24 Update patches for menu framework Sascha Hauer
2010-08-23  6:24 ` [PATCH 1/9] menu: initialize entries list in menu_alloc Sascha Hauer
2010-08-23  6:24 ` Sascha Hauer [this message]
2010-08-23  6:24 ` [PATCH 3/9] menu: simplify menu_free with list_for_each_entry_safe Sascha Hauer
2010-08-23  6:24 ` [PATCH 4/9] menu: remove superfluous struct menu_entry member from struct menu Sascha Hauer
2010-08-23  6:24 ` [PATCH 5/9] menu: use list_for_each_entry where appropriate Sascha Hauer
2010-08-23  6:24 ` [PATCH 6/9] menu: use an initialized struct list as menu list Sascha Hauer
2010-08-23  6:24 ` [PATCH 7/9] menu: fix memory corruption Sascha Hauer
2010-08-23 11:40   ` Jean-Christophe PLAGNIOL-VILLARD
2010-08-23 12:44     ` Uwe Kleine-König
2010-08-23  6:24 ` [PATCH 8/9] menu: do not go to free if there's nothing to free Sascha Hauer
2010-08-23  6:24 ` [PATCH 9/9] menu: simplify usage for clients Sascha Hauer
2010-08-23 15:18   ` Jean-Christophe PLAGNIOL-VILLARD
2010-08-23 16:49     ` Sascha Hauer
2010-08-26 16:19       ` Jean-Christophe PLAGNIOL-VILLARD

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1282544653-11508-3-git-send-email-s.hauer@pengutronix.de \
    --to=s.hauer@pengutronix.de \
    --cc=barebox@lists.infradead.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox