[OpenWrt-Devel] [PATCH] ubus: Fix Wformat-nonliteral warning

Rosen Penev rosenp at gmail.com
Fri Nov 29 16:07:56 EST 2019


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
[-Werror=format-nonliteral]
   99 |  sprintf(hreq->data, format, obj->name, msgstr);
      |  ^~~~~~~

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

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));
-- 
2.23.0


_______________________________________________
openwrt-devel mailing list
openwrt-devel at lists.openwrt.org
https://lists.openwrt.org/mailman/listinfo/openwrt-devel



More information about the openwrt-devel mailing list