提交 6735aa99 编写于 作者: C Christophe Fergeau 提交者: Gerd Hoffmann

spice-core: Use g_strdup_printf instead of snprintf

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: NChristophe Fergeau <cfergeau@redhat.com>
Signed-off-by: NGerd Hoffmann <kraxel@redhat.com>
上级 94c2b6af
...@@ -511,7 +511,9 @@ SpiceInfo *qmp_query_spice(Error **errp) ...@@ -511,7 +511,9 @@ SpiceInfo *qmp_query_spice(Error **errp)
int port, tls_port; int port, tls_port;
const char *addr; const char *addr;
SpiceInfo *info; 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)); info = g_malloc0(sizeof(*info));
...@@ -534,11 +536,10 @@ SpiceInfo *qmp_query_spice(Error **errp) ...@@ -534,11 +536,10 @@ SpiceInfo *qmp_query_spice(Error **errp)
info->host = g_strdup(addr ? addr : "0.0.0.0"); info->host = g_strdup(addr ? addr : "0.0.0.0");
info->has_compiled_version = true; info->has_compiled_version = true;
snprintf(version_string, sizeof(version_string), "%d.%d.%d", major = (SPICE_SERVER_VERSION & 0xff0000) >> 16;
(SPICE_SERVER_VERSION & 0xff0000) >> 16, minor = (SPICE_SERVER_VERSION & 0xff00) >> 8;
(SPICE_SERVER_VERSION & 0xff00) >> 8, micro = SPICE_SERVER_VERSION & 0xff;
SPICE_SERVER_VERSION & 0xff); info->compiled_version = g_strdup_printf("%d.%d.%d", major, minor, micro);
info->compiled_version = g_strdup(version_string);
if (port) { if (port) {
info->has_port = true; info->has_port = true;
...@@ -640,7 +641,7 @@ void qemu_spice_init(void) ...@@ -640,7 +641,7 @@ void qemu_spice_init(void)
char *x509_key_file = NULL, char *x509_key_file = NULL,
*x509_cert_file = NULL, *x509_cert_file = NULL,
*x509_cacert_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_image_compression_t compression;
spice_wan_compression_t wan_compr; spice_wan_compression_t wan_compr;
bool seamless_migration; bool seamless_migration;
...@@ -671,30 +672,29 @@ void qemu_spice_init(void) ...@@ -671,30 +672,29 @@ void qemu_spice_init(void)
if (NULL == x509_dir) { if (NULL == x509_dir) {
x509_dir = "."; x509_dir = ".";
} }
len = strlen(x509_dir) + 32;
str = qemu_opt_get(opts, "x509-key-file"); str = qemu_opt_get(opts, "x509-key-file");
if (str) { if (str) {
x509_key_file = g_strdup(str); x509_key_file = g_strdup(str);
} else { } else {
x509_key_file = g_malloc(len); x509_key_file = g_strdup_printf("%s/%s", x509_dir,
snprintf(x509_key_file, len, "%s/%s", x509_dir, X509_SERVER_KEY_FILE); X509_SERVER_KEY_FILE);
} }
str = qemu_opt_get(opts, "x509-cert-file"); str = qemu_opt_get(opts, "x509-cert-file");
if (str) { if (str) {
x509_cert_file = g_strdup(str); x509_cert_file = g_strdup(str);
} else { } else {
x509_cert_file = g_malloc(len); x509_cert_file = g_strdup_printf("%s/%s", x509_dir,
snprintf(x509_cert_file, len, "%s/%s", x509_dir, X509_SERVER_CERT_FILE); X509_SERVER_CERT_FILE);
} }
str = qemu_opt_get(opts, "x509-cacert-file"); str = qemu_opt_get(opts, "x509-cacert-file");
if (str) { if (str) {
x509_cacert_file = g_strdup(str); x509_cacert_file = g_strdup(str);
} else { } else {
x509_cacert_file = g_malloc(len); x509_cacert_file = g_strdup_printf("%s/%s", x509_dir,
snprintf(x509_cacert_file, len, "%s/%s", x509_dir, X509_CA_CERT_FILE); X509_CA_CERT_FILE);
} }
x509_key_password = qemu_opt_get(opts, "x509-key-password"); x509_key_password = qemu_opt_get(opts, "x509-key-password");
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册