From patchwork Wed May 16 09:25:30 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Colin Ian King X-Patchwork-Id: 159554 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from chlorine.canonical.com (chlorine.canonical.com [91.189.94.204]) by ozlabs.org (Postfix) with ESMTP id 86382B6FC4 for ; Wed, 16 May 2012 19:25:38 +1000 (EST) Received: from localhost ([127.0.0.1] helo=chlorine.canonical.com) by chlorine.canonical.com with esmtp (Exim 4.71) (envelope-from ) id 1SUaUD-0007n4-8c for incoming@patchwork.ozlabs.org; Wed, 16 May 2012 09:25:37 +0000 Received: from youngberry.canonical.com ([91.189.89.112]) by chlorine.canonical.com with esmtp (Exim 4.71) (envelope-from ) id 1SUaU7-0007iV-KI for fwts-devel@lists.ubuntu.com; Wed, 16 May 2012 09:25:31 +0000 Received: from cpc19-craw6-2-0-cust5.croy.cable.virginmedia.com ([77.102.228.6] helo=localhost) by youngberry.canonical.com with esmtpsa (TLS1.0:DHE_RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1SUaU7-0007lh-Hm for fwts-devel@lists.ubuntu.com; Wed, 16 May 2012 09:25:31 +0000 From: Colin King To: fwts-devel@lists.ubuntu.com Subject: [PATCH, RESEND] lib: fwts_args: remove strlen() calls, more efficient and stops valgrind complaining Date: Wed, 16 May 2012 10:25:30 +0100 Message-Id: <1337160330-25113-1-git-send-email-colin.king@canonical.com> X-Mailer: git-send-email 1.7.10 X-BeenThere: fwts-devel@lists.ubuntu.com X-Mailman-Version: 2.1.13 Precedence: list List-Id: Firmware Test Suite Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: fwts-devel-bounces@lists.ubuntu.com Errors-To: fwts-devel-bounces@lists.ubuntu.com From: Colin Ian King Signed-off-by: Colin Ian King Acked-by: Keng-Yu Lin Acked-by: Alex Hung Acked-by: Ivan Hu --- src/lib/src/fwts_args.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/lib/src/fwts_args.c b/src/lib/src/fwts_args.c index b5ef3e0..b9ae7dc 100644 --- a/src/lib/src/fwts_args.c +++ b/src/lib/src/fwts_args.c @@ -101,6 +101,7 @@ int fwts_args_parse(fwts_framework *fw, int argc, char * const argv[]) int option_index; int ret = FWTS_OK; char *short_options = NULL; + size_t short_options_len = 0; long_options = calloc(1, (total_options + 1) * sizeof(struct option)); if (long_options == NULL) { @@ -126,7 +127,7 @@ int fwts_args_parse(fwts_framework *fw, int argc, char * const argv[]) if (short_name && (len = strlen(short_name)) > 0) { if (short_options) { short_options = realloc(short_options, - strlen(short_options) + len + 1); + short_options_len + len + 1); if (short_options == NULL) { fwts_log_error(fw, "Out of memory " @@ -134,6 +135,7 @@ int fwts_args_parse(fwts_framework *fw, int argc, char * const argv[]) return FWTS_ERROR; } strcat(short_options, short_name); + short_options_len += (len + 1); } else { short_options = calloc(1, len + 1); if (short_options == NULL) { @@ -143,6 +145,7 @@ int fwts_args_parse(fwts_framework *fw, int argc, char * const argv[]) return FWTS_ERROR; } strcpy(short_options, short_name); + short_options_len += (len + 1); } } }