Skip to content

Commit

Permalink
tools: bpftool: fix -Wmissing declaration warnings
Browse files Browse the repository at this point in the history
Help compiler check arguments for several utility functions used to
print items to the console by adding the "printf" attribute when
declaring those functions.

Also, declare as "static" two functions that are only used in prog.c.

All of them discovered by compiling bpftool with
-Wmissing-format-attribute -Wmissing-declarations.

Signed-off-by: Quentin Monnet <quentin.monnet@netronome.com>
Reviewed-by: Jakub Kicinski <jakub.kicinski@netronome.com>
Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
  • Loading branch information
Quentin Monnet authored and Daniel Borkmann committed Dec 15, 2018
1 parent 8c03ecf commit c101189
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 9 deletions.
4 changes: 2 additions & 2 deletions tools/bpf/bpftool/common.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
#define BPF_FS_MAGIC 0xcafe4a11
#endif

void p_err(const char *fmt, ...)
void __printf(1, 2) p_err(const char *fmt, ...)
{
va_list ap;

Expand All @@ -46,7 +46,7 @@ void p_err(const char *fmt, ...)
va_end(ap);
}

void p_info(const char *fmt, ...)
void __printf(1, 2) p_info(const char *fmt, ...)
{
va_list ap;

Expand Down
6 changes: 4 additions & 2 deletions tools/bpf/bpftool/json_writer.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#include <malloc.h>
#include <inttypes.h>
#include <stdint.h>
#include <linux/compiler.h>

#include "json_writer.h"

Expand Down Expand Up @@ -157,15 +158,16 @@ void jsonw_name(json_writer_t *self, const char *name)
putc(' ', self->out);
}

void jsonw_vprintf_enquote(json_writer_t *self, const char *fmt, va_list ap)
void __printf(2, 0)
jsonw_vprintf_enquote(json_writer_t *self, const char *fmt, va_list ap)
{
jsonw_eor(self);
putc('"', self->out);
vfprintf(self->out, fmt, ap);
putc('"', self->out);
}

void jsonw_printf(json_writer_t *self, const char *fmt, ...)
void __printf(2, 3) jsonw_printf(json_writer_t *self, const char *fmt, ...)
{
va_list ap;

Expand Down
4 changes: 2 additions & 2 deletions tools/bpf/bpftool/prog.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ static const char * const attach_type_strings[] = {
[__MAX_BPF_ATTACH_TYPE] = NULL,
};

enum bpf_attach_type parse_attach_type(const char *str)
static enum bpf_attach_type parse_attach_type(const char *str)
{
enum bpf_attach_type type;

Expand Down Expand Up @@ -798,7 +798,7 @@ struct map_replace {
char *name;
};

int map_replace_compar(const void *p1, const void *p2)
static int map_replace_compar(const void *p1, const void *p2)
{
const struct map_replace *a = p1, *b = p2;

Expand Down
7 changes: 4 additions & 3 deletions tools/bpf/bpftool/xlated_dumper.c
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ struct kernel_sym *kernel_syms_search(struct dump_data *dd,
sizeof(*dd->sym_mapping), kernel_syms_cmp) : NULL;
}

static void print_insn(void *private_data, const char *fmt, ...)
static void __printf(2, 3) print_insn(void *private_data, const char *fmt, ...)
{
va_list args;

Expand All @@ -90,7 +90,7 @@ static void print_insn(void *private_data, const char *fmt, ...)
va_end(args);
}

static void
static void __printf(2, 3)
print_insn_for_graph(void *private_data, const char *fmt, ...)
{
char buf[64], *p;
Expand Down Expand Up @@ -121,7 +121,8 @@ print_insn_for_graph(void *private_data, const char *fmt, ...)
printf("%s", buf);
}

static void print_insn_json(void *private_data, const char *fmt, ...)
static void __printf(2, 3)
print_insn_json(void *private_data, const char *fmt, ...)
{
unsigned int l = strlen(fmt);
char chomped_fmt[l];
Expand Down

0 comments on commit c101189

Please sign in to comment.