[OpenWrt-Devel] ubus: Fix Wformat-nonliteral warning
diff mbox series

Message ID 20191129210756.4377-1-rosenp@gmail.com
State Superseded
Delegated to: Petr Štetiar
Headers show
  • [OpenWrt-Devel] ubus: Fix Wformat-nonliteral warning
Related show

Commit Message

Rosen Penev Nov. 29, 2019, 9:07 p.m. UTC
A const char * variable cannot be used as a format string, leading to
this warning.

This change allows GCC to check the types properly.

Fixes warning:

error: format not a string literal, argument types not checked
   99 |  sprintf(hreq->data, format, obj->name, msgstr);
      |  ^~~~~~~

Signed-off-by: Rosen Penev <rosenp@gmail.com>
 examples/server.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff mbox series

diff --git a/examples/server.c b/examples/server.c
index e0cde0b..e218efa 100644
--- a/examples/server.c
+++ b/examples/server.c
@@ -84,7 +84,7 @@  static int test_hello(struct ubus_context *ctx, struct ubus_object *obj,
 	struct hello_request *hreq;
 	struct blob_attr *tb[__HELLO_MAX];
-	const char *format = "%s received a message: %s";
+#define format "%s received a message: %s"
 	const char *msgstr = "(unknown)";
 	blobmsg_parse(hello_policy, ARRAY_SIZE(hello_policy), tb, blob_data(msg), blob_len(msg));