From patchwork Fri Jul 22 11:33:29 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christophe Fergeau X-Patchwork-Id: 106259 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [140.186.70.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 40191B6F18 for ; Fri, 22 Jul 2011 21:34:08 +1000 (EST) Received: from localhost ([::1]:57982 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1QkDzV-0006sF-5i for incoming@patchwork.ozlabs.org; Fri, 22 Jul 2011 07:34:01 -0400 Received: from eggs.gnu.org ([140.186.70.92]:39868) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1QkDz9-0005r6-Gx for qemu-devel@nongnu.org; Fri, 22 Jul 2011 07:33:40 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1QkDz7-00009h-RD for qemu-devel@nongnu.org; Fri, 22 Jul 2011 07:33:39 -0400 Received: from mx1.redhat.com ([209.132.183.28]:31501) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1QkDz7-00009X-Ix for qemu-devel@nongnu.org; Fri, 22 Jul 2011 07:33:37 -0400 Received: from int-mx09.intmail.prod.int.phx2.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id p6MBXaOH002984 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Fri, 22 Jul 2011 07:33:37 -0400 Received: from localhost.localdomain (ovpn-116-27.ams2.redhat.com [10.36.116.27]) by int-mx09.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id p6MBXUct005459 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO) for ; Fri, 22 Jul 2011 07:33:36 -0400 From: Christophe Fergeau To: qemu-devel@nongnu.org Date: Fri, 22 Jul 2011 13:33:29 +0200 Message-Id: <1311334410-28559-4-git-send-email-cfergeau@redhat.com> In-Reply-To: <1311334410-28559-1-git-send-email-cfergeau@redhat.com> References: <1311334410-28559-1-git-send-email-cfergeau@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.22 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCHv3 3/4] libcacard: replace copy_string with strndup X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org copy_string reimplements strndup, this commit removes it and replaces all copy_string uses with strndup. Signed-off-by: Christophe Fergeau Reviewed-by: Alon Levy --- libcacard/vcard_emul_nss.c | 23 ++++++----------------- 1 files changed, 6 insertions(+), 17 deletions(-) diff --git a/libcacard/vcard_emul_nss.c b/libcacard/vcard_emul_nss.c index 2a20bd6..de324ba 100644 --- a/libcacard/vcard_emul_nss.c +++ b/libcacard/vcard_emul_nss.c @@ -925,17 +925,6 @@ vcard_emul_replay_insertion_events(void) /* * Silly little functions to help parsing our argument string */ -static char * -copy_string(const char *str, int str_len) -{ - char *new_str; - - new_str = qemu_malloc(str_len+1); - memcpy(new_str, str, str_len); - new_str[str_len] = 0; - return new_str; -} - static int count_tokens(const char *str, char token, char token_end) { @@ -1054,18 +1043,18 @@ vcard_emul_options(const char *args) } opts->vreader = vreaderOpt; vreaderOpt = &vreaderOpt[opts->vreader_count]; - vreaderOpt->name = copy_string(name, name_length); - vreaderOpt->vname = copy_string(vname, vname_length); + vreaderOpt->name = qemu_strndup(name, name_length); + vreaderOpt->vname = qemu_strndup(vname, vname_length); vreaderOpt->card_type = type; vreaderOpt->type_params = - copy_string(type_params, type_params_length); + qemu_strndup(type_params, type_params_length); count = count_tokens(args, ',', ')') + 1; vreaderOpt->cert_count = count; vreaderOpt->cert_name = (char **)qemu_malloc(count*sizeof(char *)); for (i = 0; i < count; i++) { const char *cert = args; args = strpbrk(args, ",)"); - vreaderOpt->cert_name[i] = copy_string(cert, args - cert); + vreaderOpt->cert_name[i] = qemu_strndup(cert, args - cert); args = strip(args+1); } if (*args == ')') { @@ -1092,7 +1081,7 @@ vcard_emul_options(const char *args) args = strip(args+10); params = args; args = find_blank(args); - opts->hw_type_params = copy_string(params, args-params); + opts->hw_type_params = qemu_strndup(params, args-params); /* db="/data/base/path" */ } else if (strncmp(args, "db=", 3) == 0) { const char *db; @@ -1103,7 +1092,7 @@ vcard_emul_options(const char *args) args++; db = args; args = strpbrk(args, "\"\n"); - opts->nss_db = copy_string(db, args-db); + opts->nss_db = qemu_strndup(db, args-db); if (*args != 0) { args++; }