These functions can't fail really. Drop checking of their retval
then.
Signed-off-by: Michal Privoznik <mprivozn(a)redhat.com>
---
src/libxl/libxl_logger.c | 3 +--
src/qemu/qemu_domain.c | 6 ++----
src/util/viraudit.c | 3 +--
src/util/vircommand.c | 12 ++----------
src/util/virerror.c | 6 ++----
src/util/virfile.c | 29 ++++++-----------------------
src/util/virfirewall.c | 8 ++------
src/util/virlog.c | 3 +--
tests/eventtest.c | 4 ++--
tests/qemumonitortestutils.c | 4 +---
tools/virt-host-validate-common.c | 10 ++--------
tools/vsh.c | 16 ++++------------
12 files changed, 26 insertions(+), 78 deletions(-)
diff --git a/src/libxl/libxl_logger.c b/src/libxl/libxl_logger.c
index ffbc722f2c..63e2df046f 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;
+ virVasprintf(&message, 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 fe97e13c4f..a2eac8f579 100644
--- a/src/qemu/qemu_domain.c
+++ b/src/qemu/qemu_domain.c
@@ -9396,8 +9396,7 @@ int qemuDomainLogContextWrite(qemuDomainLogContextPtr ctxt,
va_start(argptr, fmt);
- if (virVasprintf(&message, fmt, argptr) < 0)
- goto cleanup;
+ virVasprintf(&message, fmt, argptr);
if (!ctxt->manager &&
lseek(ctxt->writefd, 0, SEEK_END) < 0) {
virReportSystemError(errno, "%s",
@@ -9490,8 +9489,7 @@ qemuDomainLogAppendMessage(virQEMUDriverPtr driver,
va_start(ap, fmt);
- if (virVasprintf(&message, fmt, ap) < 0)
- goto cleanup;
+ virVasprintf(&message, 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 8a0ef6f72c..1210ba8c94 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");
+ virVasprintf(&str, fmt, args);
va_end(args);
if (auditlog && str) {
diff --git a/src/util/vircommand.c b/src/util/vircommand.c
index 223a2a824e..4b9e837ff0 100644
--- a/src/util/vircommand.c
+++ b/src/util/vircommand.c
@@ -1324,11 +1324,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;
- }
+ virVasprintf(&env, format, list);
va_end(list);
virCommandAddEnv(cmd, env);
@@ -1557,11 +1553,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;
- }
+ virVasprintf(&arg, format, list);
va_end(list);
/* Arg plus trailing NULL. */
diff --git a/src/util/virerror.c b/src/util/virerror.c
index 5403caf025..a5e43361b8 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(virVasprintf(&str, fmt, ap));
+ virVasprintf(&str, fmt, ap);
va_end(ap);
}
@@ -1485,15 +1485,13 @@ virLastErrorPrefixMessage(const char *fmt, ...)
va_start(args, fmt);
- if (virVasprintf(&fmtmsg, fmt, args) < 0)
- goto cleanup;
+ virVasprintf(&fmtmsg, fmt, 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 042847137d..d2407e7068 100644
--- a/src/util/virfile.c
+++ b/src/util/virfile.c
@@ -3387,8 +3387,7 @@ int virFilePrintf(FILE *fp, const char *msg, ...)
va_start(vargs, msg);
- if (virVasprintf(&str, msg, vargs) < 0)
- goto cleanup;
+ virVasprintf(&str, 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;
- }
+ virVasprintf(&path, 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;
- }
+ virVasprintf(&path, 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;
- }
+ virVasprintf(&path, 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;
- }
+ virVasprintf(&path, 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;
- }
+ virVasprintf(&path, format, ap);
va_end(ap);
if (!virFileExists(path))
diff --git a/src/util/virfirewall.c b/src/util/virfirewall.c
index fc2c7248cb..55dfc65d0f 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;
+ virVasprintf(&arg, 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 f7ae47559f..d2c7b373cf 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 (virVasprintf(&str, fmt, vargs) < 0)
- goto cleanup;
+ virVasprintf(&str, fmt, vargs);
virLogFormatString(&msg, linenr, funcname, priority, str);
diff --git a/tests/eventtest.c b/tests/eventtest.c
index 74b2a807f3..4c553d5eb7 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 && virVasprintf(&str, msg, vargs) != 0)
- failed = true;
+ if (msg)
+ virVasprintf(&str, msg, vargs);
data.failed = failed;
data.msg = str;
diff --git a/tests/qemumonitortestutils.c b/tests/qemumonitortestutils.c
index 3c93468a4e..c522ee6a83 100644
--- a/tests/qemumonitortestutils.c
+++ b/tests/qemumonitortestutils.c
@@ -188,15 +188,13 @@ qemuMonitorReportError(qemuMonitorTestPtr test, const char *errmsg,
...)
va_start(msgargs, errmsg);
- if (virVasprintf(&msg, errmsg, msgargs) < 0)
- goto cleanup;
+ virVasprintf(&msg, 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 daeb2f0e1c..bc14227864 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();
- }
+ virVasprintf(&msg, 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();
- }
+ virVasprintf(&msg, format, args);
va_end(args);
if (virHostMsgWantEscape())
diff --git a/tools/vsh.c b/tools/vsh.c
index 7af3ce237c..b1d3bcff6d 100644
--- a/tools/vsh.c
+++ b/tools/vsh.c
@@ -1855,11 +1855,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;
- }
+ virVasprintf(&str, format, ap);
va_end(ap);
fputs(str, stdout);
VIR_FREE(str);
@@ -1875,8 +1871,7 @@ vshPrintExtra(vshControl *ctl, const char *format, ...)
return;
va_start(ap, format);
- if (virVasprintf(&str, format, ap) < 0)
- vshErrorOOM();
+ virVasprintf(&str, format, ap);
va_end(ap);
fputs(str, stdout);
VIR_FREE(str);
@@ -1890,8 +1885,7 @@ vshPrint(vshControl *ctl G_GNUC_UNUSED, const char *format, ...)
char *str;
va_start(ap, format);
- if (virVasprintf(&str, format, ap) < 0)
- vshErrorOOM();
+ virVasprintf(&str, format, ap);
va_end(ap);
fputs(str, stdout);
VIR_FREE(str);
@@ -2023,9 +2017,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));
+ virVasprintf(&str, format, ap);
va_end(ap);
fprintf(stderr, "%s\n", NULLSTR(str));
--
2.21.0