Skip to content

Commit 7c329bb

Browse files
sean-jcbonzini
authored andcommitted
KVM: selftests: Assert that vasprintf() is successful
Assert that vasprintf() succeeds as the "returned" string is undefined on failure. Checking the result also eliminates the only warning with default options in KVM selftests, i.e. is the only thing getting in the way of compile with -Werror. lib/test_util.c: In function ‘strdup_printf’: lib/test_util.c:390:9: error: ignoring return value of ‘vasprintf’ declared with attribute ‘warn_unused_result’ [-Werror=unused-result] 390 | vasprintf(&str, fmt, ap); | ^~~~~~~~~~~~~~~~~~~~~~~~ Don't bother capturing the return value, allegedly vasprintf() can only fail due to a memory allocation failure. Fixes: dfaf20a ("KVM: arm64: selftests: Replace str_with_index with strdup_printf") Cc: Andrew Jones <ajones@ventanamicro.com> Cc: Haibo Xu <haibo1.xu@intel.com> Cc: Anup Patel <anup@brainfault.org> Signed-off-by: Sean Christopherson <seanjc@google.com> Reviewed-by: Andrew Jones <ajones@ventanamicro.com> Tested-by: Andrew Jones <ajones@ventanamicro.com> Message-Id: <20230914010636.1391735-1-seanjc@google.com> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
1 parent 7c7cce2 commit 7c329bb

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

tools/testing/selftests/kvm/lib/test_util.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -387,7 +387,7 @@ char *strdup_printf(const char *fmt, ...)
387387
char *str;
388388

389389
va_start(ap, fmt);
390-
vasprintf(&str, fmt, ap);
390+
TEST_ASSERT(vasprintf(&str, fmt, ap) >= 0, "vasprintf() failed");
391391
va_end(ap);
392392

393393
return str;

0 commit comments

Comments
 (0)