From patchwork Fri Aug 17 20:49:36 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Joe Hershberger X-Patchwork-Id: 178372 X-Patchwork-Delegate: trini@ti.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from theia.denx.de (theia.denx.de [85.214.87.163]) by ozlabs.org (Postfix) with ESMTP id 2AD9D2C00C5 for ; Sat, 18 Aug 2012 06:50:31 +1000 (EST) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id F2ADE288D0; Fri, 17 Aug 2012 22:50:25 +0200 (CEST) X-Virus-Scanned: Debian amavisd-new at theia.denx.de Received: from theia.denx.de ([127.0.0.1]) by localhost (theia.denx.de [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 4qsNkE7zK8F9; Fri, 17 Aug 2012 22:50:25 +0200 (CEST) Received: from theia.denx.de (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 90D0F2882C; Fri, 17 Aug 2012 22:50:08 +0200 (CEST) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 6BC1428813 for ; Fri, 17 Aug 2012 22:50:00 +0200 (CEST) X-Virus-Scanned: Debian amavisd-new at theia.denx.de Received: from theia.denx.de ([127.0.0.1]) by localhost (theia.denx.de [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id df6yrRyImcGm for ; Fri, 17 Aug 2012 22:50:00 +0200 (CEST) X-policyd-weight: NOT_IN_SBL_XBL_SPAMHAUS=-1.5 NOT_IN_SPAMCOP=-1.5 NOT_IN_BL_NJABL=-1.5 (only DNSBL check requested) Received: from spamkiller06.natinst.com (mailserver6.natinst.com [130.164.80.6]) by theia.denx.de (Postfix) with ESMTP id 29A1028805 for ; Fri, 17 Aug 2012 22:49:57 +0200 (CEST) Received: from mailserv58-us.natinst.com (nb-hsrp-1338.natinst.com [130.164.19.133]) by spamkiller06.natinst.com (8.14.4/8.14.4) with ESMTP id q7HKnt0b024579; Fri, 17 Aug 2012 15:49:55 -0500 Received: from linux-xvxi.natinst.com ([130.164.14.197]) by mailserv58-us.natinst.com (Lotus Domino Release 8.5.2FP3) with ESMTP id 2012081715495555-1270331 ; Fri, 17 Aug 2012 15:49:55 -0500 From: Joe Hershberger To: u-boot@lists.denx.de Date: Fri, 17 Aug 2012 15:49:36 -0500 Message-Id: <1345236586-19076-3-git-send-email-joe.hershberger@ni.com> X-Mailer: git-send-email 1.7.11.5 In-Reply-To: <1345236586-19076-1-git-send-email-joe.hershberger@ni.com> References: <20100622222932.DCDB71524EE@gemini.denx.de> <1345236586-19076-1-git-send-email-joe.hershberger@ni.com> X-MIMETrack: Itemize by SMTP Server on MailServ58-US/AUS/H/NIC(Release 8.5.2FP3|July 10, 2011) at 08/17/2012 03:49:55 PM, Serialize by Router on MailServ58-US/AUS/H/NIC(Release 8.5.2FP3|July 10, 2011) at 08/17/2012 03:49:55 PM, Serialize complete at 08/17/2012 03:49:55 PM X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:5.7.7855, 1.0.260, 0.0.0000 definitions=2012-08-17_03:2012-08-17, 2012-08-17, 1970-01-01 signatures=0 Cc: Joe Hershberger Subject: [U-Boot] [PATCH 02/12] tools/env: Remove unneeded complexity X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.11 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: u-boot-bounces@lists.denx.de Errors-To: u-boot-bounces@lists.denx.de The length included the name length, and then it was subtracted back out on each use. Now we don't include it in the first place. Signed-off-by: Joe Hershberger --- tools/env/fw_env.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/tools/env/fw_env.c b/tools/env/fw_env.c index e46791d..a461dbd 100644 --- a/tools/env/fw_env.c +++ b/tools/env/fw_env.c @@ -484,22 +484,23 @@ int fw_setenv(int argc, char *argv[]) name = argv[1]; - len = strlen(name) + 2; + len = 0; for (i = 2; i < argc; ++i) len += strlen(argv[i]) + 1; /* Allocate enough place to the data string */ for (i = 2; i < argc; ++i) { char *val = argv[i]; + if (!value) { - value = (char *)malloc(len - strlen(name)); + value = (char *)malloc(len); if (!value) { fprintf(stderr, "Cannot malloc %zu bytes: %s\n", - len - strlen(name), strerror(errno)); + len, strerror(errno)); return -1; } - memset(value, 0, len - strlen(name)); + memset(value, 0, len); tmpval = value; } if (i != 2)