From 44e88cd631202e0878ea39f34a8de252d7dd528b Mon Sep 17 00:00:00 2001 From: Mike Frysinger Date: Sat, 26 Jun 2021 22:05:04 -0400 Subject: [PATCH] sim: bpf: add explicit casts when using explicit formats Since the value variable usually has an incompatible type for the wide variety of types it is printed as, add explicit casts to them all. --- sim/bpf/ChangeLog | 4 ++++ sim/bpf/bpf-helpers.c | 24 ++++++++++++------------ 2 files changed, 16 insertions(+), 12 deletions(-) diff --git a/sim/bpf/ChangeLog b/sim/bpf/ChangeLog index 7c48d289b30..b53b986472d 100644 --- a/sim/bpf/ChangeLog +++ b/sim/bpf/ChangeLog @@ -1,3 +1,7 @@ +2021-06-27 Mike Frysinger + + * bpf-helpers.c (bpf_trace_printk): Add casts to every value printf. + 2021-06-27 Mike Frysinger * bpf-helpers.c (bpf_trace_printk): Move value decl to top of scope. diff --git a/sim/bpf/bpf-helpers.c b/sim/bpf/bpf-helpers.c index 79a3a7d3702..d72c22a09be 100644 --- a/sim/bpf/bpf-helpers.c +++ b/sim/bpf/bpf-helpers.c @@ -95,16 +95,16 @@ bpf_trace_printk (SIM_CPU *current_cpu) fmt_address + i))) { case 'd': - trace_printf (sd, current_cpu, "%d", value); + trace_printf (sd, current_cpu, "%d", (int) value); break; case 'i': - trace_printf (sd, current_cpu, "%i", value); + trace_printf (sd, current_cpu, "%i", (int) value); break; case 'u': - trace_printf (sd, current_cpu, "%u", value); + trace_printf (sd, current_cpu, "%u", (unsigned int) value); break; case 'x': - trace_printf (sd, current_cpu, "%x", value); + trace_printf (sd, current_cpu, "%x", (unsigned int) value); break; case 'l': { @@ -114,16 +114,16 @@ bpf_trace_printk (SIM_CPU *current_cpu) fmt_address + i)) { case 'd': - trace_printf (sd, current_cpu, "%ld", value); + trace_printf (sd, current_cpu, "%ld", (long) value); break; case 'i': - trace_printf (sd, current_cpu, "%li", value); + trace_printf (sd, current_cpu, "%li", (long) value); break; case 'u': - trace_printf (sd, current_cpu, "%lu", value); + trace_printf (sd, current_cpu, "%lu", (unsigned long) value); break; case 'x': - trace_printf (sd, current_cpu, "%lx", value); + trace_printf (sd, current_cpu, "%lx", (unsigned long) value); break; case 'l': { @@ -132,16 +132,16 @@ bpf_trace_printk (SIM_CPU *current_cpu) switch (GETMEMUQI (current_cpu, CPU_PC_GET (current_cpu), fmt_address + i)) { case 'd': - trace_printf (sd, current_cpu, "%lld", value); + trace_printf (sd, current_cpu, "%lld", (long long) value); break; case 'i': - trace_printf (sd, current_cpu, "%lli", value); + trace_printf (sd, current_cpu, "%lli", (long long) value); break; case 'u': - trace_printf (sd, current_cpu, "%llu", value); + trace_printf (sd, current_cpu, "%llu", (unsigned long long) value); break; case 'x': - trace_printf (sd, current_cpu, "%llx", value); + trace_printf (sd, current_cpu, "%llx", (unsigned long long) value); break; default: assert (0); -- 2.30.2