diff --git a/src/libxl/libxl_logger.c b/src/libxl/libxl_logger.c index ffbc722f2c497c9b6097230b5adf8e4486ff17b4..a829142b2be35cc91bf4db9b78cd88e724e2d57e 100644 --- a/src/libxl/libxl_logger.c +++ b/src/libxl/libxl_logger.c @@ -74,8 +74,7 @@ libvirt_vmessage(xentoollog_logger *logger_in, if (level < lg->minLevel) return; - if (virVasprintf(&message, format, args) < 0) - return; + message = g_strdup_vprintf(format, args); /* Should we print to a domain-specific log file? */ if ((start = strstr(message, ": Domain ")) && diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c index ebd486630f2eca06f84a8a02b30c33964aed6e56..9c517597bb6a5279165b041269c72b74d6f670ef 100644 --- a/src/qemu/qemu_domain.c +++ b/src/qemu/qemu_domain.c @@ -9430,8 +9430,7 @@ int qemuDomainLogContextWrite(qemuDomainLogContextPtr ctxt, va_start(argptr, fmt); - if (virVasprintf(&message, fmt, argptr) < 0) - goto cleanup; + message = g_strdup_vprintf(fmt, argptr); if (!ctxt->manager && lseek(ctxt->writefd, 0, SEEK_END) < 0) { virReportSystemError(errno, "%s", @@ -9524,8 +9523,7 @@ qemuDomainLogAppendMessage(virQEMUDriverPtr driver, va_start(ap, fmt); - if (virVasprintf(&message, fmt, ap) < 0) - goto cleanup; + message = g_strdup_vprintf(fmt, ap); VIR_DEBUG("Append log message (vm='%s' message='%s) stdioLogD=%d", vm->def->name, message, cfg->stdioLogD); diff --git a/src/util/viraudit.c b/src/util/viraudit.c index 8a0ef6f72c1b12f2ab1c7b7a0e76a1e32896192f..20eb3f36216f5d08bf7b5af0789db599d99dc9a9 100644 --- a/src/util/viraudit.c +++ b/src/util/viraudit.c @@ -110,8 +110,7 @@ void virAuditSend(virLogSourcePtr source, #endif va_start(args, fmt); - if (virVasprintf(&str, fmt, args) < 0) - VIR_WARN("Out of memory while formatting audit message"); + str = g_strdup_vprintf(fmt, args); va_end(args); if (auditlog && str) { diff --git a/src/util/vircommand.c b/src/util/vircommand.c index b439bbef13177117e2d47cc68a86a5c45d96b8fd..fadc7e31fadb8857ca447af1881afc4fa52baad6 100644 --- a/src/util/vircommand.c +++ b/src/util/vircommand.c @@ -1314,11 +1314,7 @@ virCommandAddEnvFormat(virCommandPtr cmd, const char *format, ...) return; va_start(list, format); - if (virVasprintf(&env, format, list) < 0) { - cmd->has_error = ENOMEM; - va_end(list); - return; - } + env = g_strdup_vprintf(format, list); va_end(list); virCommandAddEnv(cmd, env); @@ -1541,11 +1537,7 @@ virCommandAddArgFormat(virCommandPtr cmd, const char *format, ...) return; va_start(list, format); - if (virVasprintf(&arg, format, list) < 0) { - cmd->has_error = ENOMEM; - va_end(list); - return; - } + arg = g_strdup_vprintf(format, list); va_end(list); /* Arg plus trailing NULL. */ diff --git a/src/util/virerror.c b/src/util/virerror.c index 76a75e27a8d861712ac1877f396375c630e6c8ed..54cd5b64b9616c39f94771b27c4d0047a27a6163 100644 --- a/src/util/virerror.c +++ b/src/util/virerror.c @@ -830,7 +830,7 @@ virRaiseErrorFull(const char *filename, } else { va_list ap; va_start(ap, fmt); - ignore_value(virVasprintfQuiet(&str, fmt, ap)); + str = g_strdup_vprintf(fmt, ap); va_end(ap); } @@ -1484,16 +1484,13 @@ virLastErrorPrefixMessage(const char *fmt, ...) return; va_start(args, fmt); - - if (virVasprintfQuiet(&fmtmsg, fmt, args) < 0) - goto cleanup; + fmtmsg = g_strdup_vprintf(fmt, args); + va_end(args); newmsg = g_strdup_printf("%s: %s", fmtmsg, err->message); VIR_FREE(err->message); err->message = g_steal_pointer(&newmsg); - cleanup: - va_end(args); errno = save_errno; } diff --git a/src/util/virfile.c b/src/util/virfile.c index 042847137d1e4e524873f3f98380b45bc085f140..7382f8e19a557a3315bf0d89d44997569f4c6790 100644 --- a/src/util/virfile.c +++ b/src/util/virfile.c @@ -3374,9 +3374,9 @@ virFileRemoveLastComponent(char *path) /** * virFilePrintf: * - * A replacement for fprintf() which uses virVasprintf to - * ensure that portable string format placeholders can be - * used, since gnulib's fprintf() replacement is not + * A replacement for fprintf() which uses g_strdup_vprintf + * to ensure that portable string format placeholders can + * be used, since gnulib's fprintf() replacement is not * LGPLV2+ compatible */ int virFilePrintf(FILE *fp, const char *msg, ...) @@ -3387,8 +3387,7 @@ int virFilePrintf(FILE *fp, const char *msg, ...) va_start(vargs, msg); - if (virVasprintf(&str, msg, vargs) < 0) - goto cleanup; + str = g_strdup_vprintf(msg, vargs); ret = strlen(str); if (fwrite(str, 1, ret, fp) != ret) { @@ -3397,7 +3396,6 @@ int virFilePrintf(FILE *fp, const char *msg, ...) ret = -1; } - cleanup: va_end(vargs); return ret; @@ -4149,10 +4147,7 @@ virFileReadValueInt(int *value, const char *format, ...) va_list ap; va_start(ap, format); - if (virVasprintf(&path, format, ap) < 0) { - va_end(ap); - return -1; - } + path = g_strdup_vprintf(format, ap); va_end(ap); if (!virFileExists(path)) @@ -4192,10 +4187,7 @@ virFileReadValueUint(unsigned int *value, const char *format, ...) va_list ap; va_start(ap, format); - if (virVasprintf(&path, format, ap) < 0) { - va_end(ap); - return -1; - } + path = g_strdup_vprintf(format, ap); va_end(ap); if (!virFileExists(path)) @@ -4236,10 +4228,7 @@ virFileReadValueScaledInt(unsigned long long *value, const char *format, ...) va_list ap; va_start(ap, format); - if (virVasprintf(&path, format, ap) < 0) { - va_end(ap); - return -1; - } + path = g_strdup_vprintf(format, ap); va_end(ap); if (!virFileExists(path)) @@ -4282,10 +4271,7 @@ virFileReadValueBitmap(virBitmapPtr *value, const char *format, ...) va_list ap; va_start(ap, format); - if (virVasprintf(&path, format, ap) < 0) { - va_end(ap); - return -1; - } + path = g_strdup_vprintf(format, ap); va_end(ap); if (!virFileExists(path)) @@ -4323,10 +4309,7 @@ virFileReadValueString(char **value, const char *format, ...) va_list ap; va_start(ap, format); - if (virVasprintf(&path, format, ap) < 0) { - va_end(ap); - return -1; - } + path = g_strdup_vprintf(format, ap); va_end(ap); if (!virFileExists(path)) diff --git a/src/util/virfirewall.c b/src/util/virfirewall.c index fc2c7248cb0c712b1d05e35256c41224b8328520..ee72b579e43ab274a7e996ec902784b9fdd5b6b0 100644 --- a/src/util/virfirewall.c +++ b/src/util/virfirewall.c @@ -509,19 +509,15 @@ void virFirewallRuleAddArgFormat(virFirewallPtr firewall, VIR_FIREWALL_RULE_RETURN_IF_ERROR(firewall, rule); va_start(list, fmt); - - if (virVasprintf(&arg, fmt, list) < 0) - goto no_memory; + arg = g_strdup_vprintf(fmt, list); + va_end(list); ADD_ARG(rule, arg); - va_end(list); - return; no_memory: firewall->err = ENOMEM; - va_end(list); } diff --git a/src/util/virlog.c b/src/util/virlog.c index 49af8142add05b0cd92affcf91420e57c724b9bc..b3460d85fe7c43c2d7df3a5e141e2e71c5e4d107 100644 --- a/src/util/virlog.c +++ b/src/util/virlog.c @@ -594,8 +594,7 @@ virLogVMessage(virLogSourcePtr source, /* * serialize the error message, add level and timestamp */ - if (virVasprintfQuiet(&str, fmt, vargs) < 0) - goto cleanup; + str = g_strdup_vprintf(fmt, vargs); virLogFormatString(&msg, linenr, funcname, priority, str); diff --git a/tests/eventtest.c b/tests/eventtest.c index 363fc776fdfc9bfba151d46362400a94ffc394c9..fdd732f7fa1941344767e3d8141dfba6a53e9ad7 100644 --- a/tests/eventtest.c +++ b/tests/eventtest.c @@ -89,8 +89,8 @@ testEventReport(const char *name, bool failed, const char *msg, ...) char *str = NULL; struct testEventResultData data; - if (msg && virVasprintfQuiet(&str, msg, vargs) != 0) - failed = true; + if (msg) + str = g_strdup_vprintf(msg, vargs); data.failed = failed; data.msg = str; diff --git a/tests/qemumonitortestutils.c b/tests/qemumonitortestutils.c index 82a44be935b16e4b67728ce6e51496f8c4be1ece..d7ecdb2ef92c13395b3651e060498122321ef702 100644 --- a/tests/qemumonitortestutils.c +++ b/tests/qemumonitortestutils.c @@ -186,15 +186,13 @@ qemuMonitorReportError(qemuMonitorTestPtr test, const char *errmsg, ...) va_start(msgargs, errmsg); - if (virVasprintf(&msg, errmsg, msgargs) < 0) - goto cleanup; + msg = g_strdup_vprintf(errmsg, msgargs); jsonmsg = g_strdup_printf("{ \"error\": " " { \"desc\": \"%s\", " " \"class\": \"UnexpectedCommand\" } }", msg); ret = qemuMonitorTestAddResponse(test, jsonmsg); - cleanup: va_end(msgargs); return ret; } diff --git a/tools/virt-host-validate-common.c b/tools/virt-host-validate-common.c index daeb2f0e1c1f0b0ce5dcebc2aabe922e2b439dbd..af8def21f33f28569e45eb3cb33ba9e52b15a609 100644 --- a/tools/virt-host-validate-common.c +++ b/tools/virt-host-validate-common.c @@ -59,10 +59,7 @@ void virHostMsgCheck(const char *prefix, return; va_start(args, format); - if (virVasprintf(&msg, format, args) < 0) { - perror("malloc"); - abort(); - } + msg = g_strdup_vprintf(format, args); va_end(args); fprintf(stdout, _("%6s: Checking %-60s: "), prefix, msg); @@ -120,10 +117,7 @@ void virHostMsgFail(virHostValidateLevel level, return; va_start(args, format); - if (virVasprintf(&msg, format, args) < 0) { - perror("malloc"); - abort(); - } + msg = g_strdup_vprintf(format, args); va_end(args); if (virHostMsgWantEscape()) diff --git a/tools/vsh.c b/tools/vsh.c index accb4fd94bca58e5865feda0d099ad945d4d6574..271d18a5223f1f53e831fd84f4daa5abbb5f1fb4 100644 --- a/tools/vsh.c +++ b/tools/vsh.c @@ -1847,11 +1847,7 @@ vshDebug(vshControl *ctl, int level, const char *format, ...) va_end(ap); va_start(ap, format); - if (virVasprintf(&str, format, ap) < 0) { - /* Skip debug messages on low memory */ - va_end(ap); - return; - } + str = g_strdup_vprintf(format, ap); va_end(ap); fputs(str, stdout); VIR_FREE(str); @@ -1867,8 +1863,7 @@ vshPrintExtra(vshControl *ctl, const char *format, ...) return; va_start(ap, format); - if (virVasprintfQuiet(&str, format, ap) < 0) - vshErrorOOM(); + str = g_strdup_vprintf(format, ap); va_end(ap); fputs(str, stdout); VIR_FREE(str); @@ -1882,8 +1877,7 @@ vshPrint(vshControl *ctl G_GNUC_UNUSED, const char *format, ...) char *str; va_start(ap, format); - if (virVasprintfQuiet(&str, format, ap) < 0) - vshErrorOOM(); + str = g_strdup_vprintf(format, ap); va_end(ap); fputs(str, stdout); VIR_FREE(str); @@ -2015,9 +2009,7 @@ vshError(vshControl *ctl, const char *format, ...) fputs(_("error: "), stderr); va_start(ap, format); - /* We can't recursively call vshError on an OOM situation, so ignore - failure here. */ - ignore_value(virVasprintf(&str, format, ap)); + str = g_strdup_vprintf(format, ap); va_end(ap); fprintf(stderr, "%s\n", NULLSTR(str));