Functions with printf style must be declared with __attribute__((format(printf, Otherwise there is this compilation error: error: format string is not a string literal
Other errors fixed: - "%*s" must match an int value - "% " is not a valid printf format string Signed-off-by: Thomas Monjalon <tho...@monjalon.net> --- app/Makefile | 3 --- app/pktgen-log.c | 1 + lib/cli/cli.c | 2 +- lib/cli/cli_common.h | 1 + lib/cli/cli_map.c | 2 +- lib/cli/cli_scrn.c | 3 +++ lib/cli/cli_scrn.h | 1 + 7 files changed, 8 insertions(+), 5 deletions(-) diff --git a/app/Makefile b/app/Makefile index b290c8d..5bddb07 100644 --- a/app/Makefile +++ b/app/Makefile @@ -43,9 +43,6 @@ include $(RTE_SDK)/mk/rte.vars.mk # binary name APP = pktgen -CFLAGS_commands.o := -Wno-format-nonliteral -CFLAGS_pktgen-log.o := -Wno-format-nonliteral - CFLAGS += -O3 -g $(WERROR_FLAGS) -fno-stack-protector CFLAGS += -I$(RTE_SRCDIR) -I$(RTE_SRCDIR)/../lib/common diff --git a/app/pktgen-log.c b/app/pktgen-log.c index 019834c..598eb1f 100644 --- a/app/pktgen-log.c +++ b/app/pktgen-log.c @@ -99,6 +99,7 @@ pktgen_log_set_screen_level(int level) /* Log the provided message to the log screen and optionally a file. */ void +__attribute__((format(printf, 5, 6))) pktgen_log(int level, const char *file, long line, const char *func, const char *fmt, ...) { diff --git a/lib/cli/cli.c b/lib/cli/cli.c index d833947..bba0eb3 100644 --- a/lib/cli/cli.c +++ b/lib/cli/cli.c @@ -696,7 +696,7 @@ cli_pause(const char *msg, const char *keys) if (cli_poll(&c)) if (strchr(keys, c)) { /* clear the line of the prompt */ - cli_printf("\r%*s\r", strlen(prompt), " "); + cli_printf("\r%*s\r", (int)strlen(prompt), " "); return c; } } while (this_cli->quit_flag == 0); diff --git a/lib/cli/cli_common.h b/lib/cli/cli_common.h index 476d40e..59c2de5 100644 --- a/lib/cli/cli_common.h +++ b/lib/cli/cli_common.h @@ -71,6 +71,7 @@ extern "C" { */ static inline void +__attribute__((format(printf, 1, 2))) cli_printf(const char *fmt, ...) { va_list vaList; diff --git a/lib/cli/cli_map.c b/lib/cli/cli_map.c index 4fd5181..0fa34f8 100644 --- a/lib/cli/cli_map.c +++ b/lib/cli/cli_map.c @@ -162,7 +162,7 @@ decode_map(const char *fmt) } switch (fmt[1]) { - case '%': cli_printf("% "); break; + case '%': cli_printf("%% "); break; case 'd': cli_printf("<32bit number> "); break; case 'D': cli_printf("<64bit number> "); break; case 'h': cli_printf("<32bit hex> "); break; diff --git a/lib/cli/cli_scrn.c b/lib/cli/cli_scrn.c index b195e92..692698e 100644 --- a/lib/cli/cli_scrn.c +++ b/lib/cli/cli_scrn.c @@ -50,6 +50,7 @@ RTE_DEFINE_PER_LCORE(struct cli_scrn *, scrn); void +__attribute__((format(printf, 3, 4))) scrn_printf(int16_t r, int16_t c, const char *fmt, ...) { va_list vaList; @@ -63,6 +64,7 @@ scrn_printf(int16_t r, int16_t c, const char *fmt, ...) } void +__attribute__((format(printf, 3, 4))) scrn_cprintf(int16_t r, int16_t ncols, const char *fmt, ...) { va_list vaList; @@ -80,6 +82,7 @@ scrn_cprintf(int16_t r, int16_t ncols, const char *fmt, ...) } void +__attribute__((format(printf, 4, 5))) scrn_fprintf(int16_t r, int16_t c, FILE *f, const char *fmt, ...) { va_list vaList; diff --git a/lib/cli/cli_scrn.h b/lib/cli/cli_scrn.h index c841623..1bfb8f0 100644 --- a/lib/cli/cli_scrn.h +++ b/lib/cli/cli_scrn.h @@ -106,6 +106,7 @@ typedef enum { typedef uint8_t cli_rgb_t; static inline void +__attribute__((format(printf, 1, 2))) scrn_puts(const char *fmt, ...) { struct cli_scrn *scrn = this_scrn; -- 2.13.2