DPDK patches and discussions
 help / color / mirror / Atom feed
From: Thomas Monjalon <thomas@monjalon.net>
To: keith.wiles@intel.com
Cc: dev@dpdk.org
Subject: [dpdk-dev] [pktgen PATCH 3/6] fix compilation of printf based functions
Date: Wed, 26 Jul 2017 01:21:04 +0300	[thread overview]
Message-ID: <20170725222107.23203-4-thomas@monjalon.net> (raw)
In-Reply-To: <20170725222107.23203-1-thomas@monjalon.net>

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 <thomas@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

  parent reply	other threads:[~2017-07-25 22:21 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-07-25 22:21 [dpdk-dev] [pktgen PATCH 0/6] fix compilation Thomas Monjalon
2017-07-25 22:21 ` [dpdk-dev] [pktgen PATCH 1/6] remove unused functions Thomas Monjalon
2017-07-25 22:21 ` [dpdk-dev] [pktgen PATCH 2/6] fix screen type saving Thomas Monjalon
2017-07-25 22:21 ` Thomas Monjalon [this message]
2017-07-25 22:21 ` [dpdk-dev] [pktgen PATCH 4/6] fix compilation with gcc 7 Thomas Monjalon
2017-07-25 22:21 ` [dpdk-dev] [pktgen PATCH 5/6] fix 32-bit build Thomas Monjalon
2017-07-25 22:21 ` [dpdk-dev] [pktgen PATCH 6/6] fix build with dpdk-17.08-rc2 Thomas Monjalon
2017-07-26  3:54 ` [dpdk-dev] [pktgen PATCH 0/6] fix compilation Wiles, Keith
2017-07-26  4:40   ` Roberts, Lee A.
2017-07-26  5:39   ` Thomas Monjalon
2017-07-26 14:35     ` [dpdk-dev] hierarchy_commit() message displayed when not using TM Wiles, Keith
2017-07-26 14:58       ` Lu, Wenzhuo
2017-07-26 14:52     ` [dpdk-dev] [pktgen PATCH 0/6] fix compilation Wiles, Keith
2017-07-26 15:01       ` Thomas Monjalon

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20170725222107.23203-4-thomas@monjalon.net \
    --to=thomas@monjalon.net \
    --cc=dev@dpdk.org \
    --cc=keith.wiles@intel.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).