Re: [PATCH v3] tools/bpf: Fix the wrong format specifier

From: Markus Elfring
Date: Wed Jul 24 2024 - 10:39:47 EST


> The format specifier of "unsigned int" in printf() should be "%u", not
> "%d".

Would you like to add any tags (like “Fixes” and “Cc”) accordingly?



> ---
> Changes:

> v3:fix compile warninf

V3:
Fix a compilation warning?



> +++ b/tools/bpf/bpftool/xlated_dumper.c
> @@ -316,7 +316,7 @@ void dump_xlated_plain(struct dump_data *dd, void *buf, unsigned int len,

> - unsigned int i;
> + int i;

Please do not change the data type for the variable
if you would like to adjust a subsequent format string.



> @@ -415,7 +415,7 @@ void dump_xlated_for_graph(struct dump_data *dd, void *buf_start, void *buf_end,
> }
> }
>
> - printf("%d: ", insn_off);
> + printf("%u: ", insn_off);
> print_bpf_insn(&cbs, cur, true);


How do you think about to care more also for the return value from such a function call?
https://wiki.sei.cmu.edu/confluence/display/c/ERR33-C.+Detect+and+handle+standard+library+errors

Regards,
Markus