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

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


A const char * variable is being passed as a format string. Unfortunately,
this is not correct.

A constant expression needs to be passed so that GCC can determine the
types of the format properly.

Fixes:

error: format not a string literal, argument types not checked
[-Werror=format-nonliteral]
  176 |    error_info);
      |    ^~~~~~~~~~
error: format not a string literal, argument types not checked
[-Werror=format-nonliteral]
  185 |    error_info);

Signed-off-by: Rosen Penev <rosenp at gmail.com>
---
 libuci.c | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/libuci.c b/libuci.c
index a9e70e8..96da49b 100644
--- a/libuci.c
+++ b/libuci.c
@@ -142,11 +142,11 @@ uci_get_errorstr(struct uci_context *ctx, char **dest, const char *prefix)
 {
 	static char error_info[128];
 	int err;
-	const char *format =
-		"%s%s" /* prefix */
-		"%s%s" /* function */
-		"%s" /* error */
-		"%s"; /* details */
+#define	format \
+		"%s%s" /* prefix */ \
+		"%s%s" /* function */ \
+		"%s" /* error */ \
+		"%s" /* details */
 
 	error_info[0] = 0;
 
-- 
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