From patchwork Wed May 16 09:21:31 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: lib: fwts_args: remove strlen() calls, more efficient and stops valgrind complaining Date: Tue, 15 May 2012 23:21:31 -0000 From: Colin King X-Patchwork-Id: 159553 Message-Id: <1337160091-21429-1-git-send-email-colin.king@canonical.com> To: fwts-devel@lists.ubuntu.com From: Colin Ian King Signed-off-by: Colin Ian King --- 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; + ssize_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); } } }