Skip to content

Commit 1b2658e

Browse files
committed
KVM: selftests: Annotate guest ucall, printf, and assert helpers with __printf()
Annotate guest printf helpers with __printf() so that the compiler will warn about incorrect formatting at compile time (see git log for how easy it is to screw up with the formatting). Suggested-by: Maxim Levitsky <mlevitsk@redhat.com> Link: https://lore.kernel.org/r/20231129224916.532431-5-seanjc@google.com Signed-off-by: Sean Christopherson <seanjc@google.com>
1 parent f813e6d commit 1b2658e

2 files changed

Lines changed: 5 additions & 4 deletions

File tree

tools/testing/selftests/kvm/include/test_util.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ static inline uint32_t atoi_non_negative(const char *name, const char *num_str)
191191
}
192192

193193
int guest_vsnprintf(char *buf, int n, const char *fmt, va_list args);
194-
int guest_snprintf(char *buf, int n, const char *fmt, ...);
194+
__printf(3, 4) int guest_snprintf(char *buf, int n, const char *fmt, ...);
195195

196196
char *strdup_printf(const char *fmt, ...) __attribute__((format(printf, 1, 2), nonnull(1)));
197197

tools/testing/selftests/kvm/include/ucall_common.h

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,10 @@ void ucall_arch_do_ucall(vm_vaddr_t uc);
3434
void *ucall_arch_get_ucall(struct kvm_vcpu *vcpu);
3535

3636
void ucall(uint64_t cmd, int nargs, ...);
37-
void ucall_fmt(uint64_t cmd, const char *fmt, ...);
38-
void ucall_assert(uint64_t cmd, const char *exp, const char *file,
39-
unsigned int line, const char *fmt, ...);
37+
__printf(2, 3) void ucall_fmt(uint64_t cmd, const char *fmt, ...);
38+
__printf(5, 6) void ucall_assert(uint64_t cmd, const char *exp,
39+
const char *file, unsigned int line,
40+
const char *fmt, ...);
4041
uint64_t get_ucall(struct kvm_vcpu *vcpu, struct ucall *uc);
4142
void ucall_init(struct kvm_vm *vm, vm_paddr_t mmio_gpa);
4243
int ucall_nr_pages_required(uint64_t page_size);

0 commit comments

Comments
 (0)