* [Qemu-devel] [PATCH] spice-core: Use g_strdup_printf instead of snprintf
@ 2013-09-02 9:53 Christophe Fergeau
2013-09-02 10:30 ` Marc-André Lureau
2013-09-02 11:36 ` Gerd Hoffmann
0 siblings, 2 replies; 4+ messages in thread
From: Christophe Fergeau @ 2013-09-02 9:53 UTC (permalink / raw)
To: qemu-devel
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 <cfergeau@redhat.com>
---
ui/spice-core.c | 22 ++++++++--------------
1 file changed, 8 insertions(+), 14 deletions(-)
diff --git a/ui/spice-core.c b/ui/spice-core.c
index bd7a248..01b9906 100644
--- a/ui/spice-core.c
+++ b/ui/spice-core.c
@@ -511,7 +511,6 @@ 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 */
info = g_malloc0(sizeof(*info));
@@ -534,11 +533,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);
+ info->compiled_version = g_strdup_printf("%d.%d.%d",
+ (SPICE_SERVER_VERSION & 0xff0000) >> 16,
+ (SPICE_SERVER_VERSION & 0xff00) >> 8,
+ SPICE_SERVER_VERSION & 0xff);
if (port) {
info->has_port = true;
@@ -640,7 +638,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 +669,26 @@ 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");
--
1.8.3.1
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [Qemu-devel] [PATCH] spice-core: Use g_strdup_printf instead of snprintf
2013-09-02 9:53 [Qemu-devel] [PATCH] spice-core: Use g_strdup_printf instead of snprintf Christophe Fergeau
@ 2013-09-02 10:30 ` Marc-André Lureau
2013-09-02 11:36 ` Gerd Hoffmann
1 sibling, 0 replies; 4+ messages in thread
From: Marc-André Lureau @ 2013-09-02 10:30 UTC (permalink / raw)
To: Christophe Fergeau; +Cc: qemu-devel
ack
On Mon, Sep 2, 2013 at 11:53 AM, Christophe Fergeau <cfergeau@redhat.com> wrote:
> 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 <cfergeau@redhat.com>
> ---
> ui/spice-core.c | 22 ++++++++--------------
> 1 file changed, 8 insertions(+), 14 deletions(-)
>
> diff --git a/ui/spice-core.c b/ui/spice-core.c
> index bd7a248..01b9906 100644
> --- a/ui/spice-core.c
> +++ b/ui/spice-core.c
> @@ -511,7 +511,6 @@ 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 */
>
> info = g_malloc0(sizeof(*info));
>
> @@ -534,11 +533,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);
> + info->compiled_version = g_strdup_printf("%d.%d.%d",
> + (SPICE_SERVER_VERSION & 0xff0000) >> 16,
> + (SPICE_SERVER_VERSION & 0xff00) >> 8,
> + SPICE_SERVER_VERSION & 0xff);
>
> if (port) {
> info->has_port = true;
> @@ -640,7 +638,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 +669,26 @@ 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");
> --
> 1.8.3.1
>
>
--
Marc-André Lureau
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [Qemu-devel] [PATCH] spice-core: Use g_strdup_printf instead of snprintf
2013-09-02 9:53 [Qemu-devel] [PATCH] spice-core: Use g_strdup_printf instead of snprintf Christophe Fergeau
2013-09-02 10:30 ` Marc-André Lureau
@ 2013-09-02 11:36 ` Gerd Hoffmann
2013-09-02 13:44 ` Christophe Fergeau
1 sibling, 1 reply; 4+ messages in thread
From: Gerd Hoffmann @ 2013-09-02 11:36 UTC (permalink / raw)
To: Christophe Fergeau; +Cc: qemu-devel
On Mo, 2013-09-02 at 11:53 +0200, Christophe Fergeau wrote:
> 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.
Patch looks good but fails checkpatch.pl due to long lines.
cheers,
Gerd
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [Qemu-devel] [PATCH] spice-core: Use g_strdup_printf instead of snprintf
2013-09-02 11:36 ` Gerd Hoffmann
@ 2013-09-02 13:44 ` Christophe Fergeau
0 siblings, 0 replies; 4+ messages in thread
From: Christophe Fergeau @ 2013-09-02 13:44 UTC (permalink / raw)
To: Gerd Hoffmann; +Cc: qemu-devel
[-- Attachment #1: Type: text/plain, Size: 404 bytes --]
On Mon, Sep 02, 2013 at 01:36:19PM +0200, Gerd Hoffmann wrote:
> On Mo, 2013-09-02 at 11:53 +0200, Christophe Fergeau wrote:
> > 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.
>
> Patch looks good but fails checkpatch.pl due to long lines.
Ah right, I forgot to run it, I just sent a v2.
Christophe
[-- Attachment #2: Type: application/pgp-signature, Size: 198 bytes --]
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2013-09-02 13:44 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-09-02 9:53 [Qemu-devel] [PATCH] spice-core: Use g_strdup_printf instead of snprintf Christophe Fergeau
2013-09-02 10:30 ` Marc-André Lureau
2013-09-02 11:36 ` Gerd Hoffmann
2013-09-02 13:44 ` Christophe Fergeau
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).