From patchwork Tue Sep 10 10:06:10 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gerd Hoffmann X-Patchwork-Id: 273822 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id DDE022C00CA for ; Tue, 10 Sep 2013 20:07:58 +1000 (EST) Received: from localhost ([::1]:56791 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VJKrU-0005cB-Mn for incoming@patchwork.ozlabs.org; Tue, 10 Sep 2013 06:07:56 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:45732) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VJKq5-0003vR-NP for qemu-devel@nongnu.org; Tue, 10 Sep 2013 06:06:35 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1VJKpv-0004PW-WB for qemu-devel@nongnu.org; Tue, 10 Sep 2013 06:06:29 -0400 Received: from mx1.redhat.com ([209.132.183.28]:28713) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VJKpv-0004PP-OP for qemu-devel@nongnu.org; Tue, 10 Sep 2013 06:06:19 -0400 Received: from int-mx01.intmail.prod.int.phx2.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id r8AA6Ib2004366 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Tue, 10 Sep 2013 06:06:18 -0400 Received: from nilsson.home.kraxel.org (vpn1-4-143.ams2.redhat.com [10.36.4.143]) by int-mx01.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id r8AA6GGC002988; Tue, 10 Sep 2013 06:06:17 -0400 Received: by nilsson.home.kraxel.org (Postfix, from userid 500) id 1FC1080701; Tue, 10 Sep 2013 12:06:16 +0200 (CEST) From: Gerd Hoffmann To: qemu-devel@nongnu.org Date: Tue, 10 Sep 2013 12:06:10 +0200 Message-Id: <1378807572-27902-2-git-send-email-kraxel@redhat.com> In-Reply-To: <1378807572-27902-1-git-send-email-kraxel@redhat.com> References: <1378807572-27902-1-git-send-email-kraxel@redhat.com> X-Scanned-By: MIMEDefang 2.67 on 10.5.11.11 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 209.132.183.28 Cc: Anthony Liguori , Gerd Hoffmann , Christophe Fergeau Subject: [Qemu-devel] [PATCH 1/3] spice-core: Use g_strdup_printf instead of snprintf 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 From: Christophe Fergeau Several places in spice-core.c were using either g_malloc+snprintf or snprintf+g_strdup to achieve the same result as g_strdup_printf. Signed-off-by: Christophe Fergeau Signed-off-by: Gerd Hoffmann --- ui/spice-core.c | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/ui/spice-core.c b/ui/spice-core.c index 3a2cd7e..33ef837 100644 --- a/ui/spice-core.c +++ b/ui/spice-core.c @@ -511,7 +511,9 @@ SpiceInfo *qmp_query_spice(Error **errp) int port, tls_port; const char *addr; SpiceInfo *info; - char version_string[20]; /* 12 = |255.255.255\0| is the max */ + unsigned int major; + unsigned int minor; + unsigned int micro; info = g_malloc0(sizeof(*info)); @@ -534,11 +536,10 @@ SpiceInfo *qmp_query_spice(Error **errp) info->host = g_strdup(addr ? addr : "0.0.0.0"); info->has_compiled_version = true; - snprintf(version_string, sizeof(version_string), "%d.%d.%d", - (SPICE_SERVER_VERSION & 0xff0000) >> 16, - (SPICE_SERVER_VERSION & 0xff00) >> 8, - SPICE_SERVER_VERSION & 0xff); - info->compiled_version = g_strdup(version_string); + major = (SPICE_SERVER_VERSION & 0xff0000) >> 16; + minor = (SPICE_SERVER_VERSION & 0xff00) >> 8; + micro = SPICE_SERVER_VERSION & 0xff; + info->compiled_version = g_strdup_printf("%d.%d.%d", major, minor, micro); if (port) { info->has_port = true; @@ -640,7 +641,7 @@ void qemu_spice_init(void) char *x509_key_file = NULL, *x509_cert_file = NULL, *x509_cacert_file = NULL; - int port, tls_port, len, addr_flags; + int port, tls_port, addr_flags; spice_image_compression_t compression; spice_wan_compression_t wan_compr; bool seamless_migration; @@ -671,30 +672,29 @@ void qemu_spice_init(void) if (NULL == x509_dir) { x509_dir = "."; } - len = strlen(x509_dir) + 32; str = qemu_opt_get(opts, "x509-key-file"); if (str) { x509_key_file = g_strdup(str); } else { - x509_key_file = g_malloc(len); - snprintf(x509_key_file, len, "%s/%s", x509_dir, X509_SERVER_KEY_FILE); + x509_key_file = g_strdup_printf("%s/%s", x509_dir, + X509_SERVER_KEY_FILE); } str = qemu_opt_get(opts, "x509-cert-file"); if (str) { x509_cert_file = g_strdup(str); } else { - x509_cert_file = g_malloc(len); - snprintf(x509_cert_file, len, "%s/%s", x509_dir, X509_SERVER_CERT_FILE); + x509_cert_file = g_strdup_printf("%s/%s", x509_dir, + X509_SERVER_CERT_FILE); } str = qemu_opt_get(opts, "x509-cacert-file"); if (str) { x509_cacert_file = g_strdup(str); } else { - x509_cacert_file = g_malloc(len); - snprintf(x509_cacert_file, len, "%s/%s", x509_dir, X509_CA_CERT_FILE); + x509_cacert_file = g_strdup_printf("%s/%s", x509_dir, + X509_CA_CERT_FILE); } x509_key_password = qemu_opt_get(opts, "x509-key-password");