char is signed on common platforms. Passing a "negative" string byte to
isprint() is undefined behavior when it is not EOF. The manpage for isprint
is therefore requesting to provide the argument as unsigned char.

Fixes: ae1a3d3f0bb7 ("batctl: genl_json: Add generic JSON interface")
Signed-off-by: Sven Eckelmann <[email protected]>
---
 genl_json.c | 16 +++++++++-------
 1 file changed, 9 insertions(+), 7 deletions(-)

diff --git a/genl_json.c b/genl_json.c
index 8aa97b4..ee83ab2 100644
--- a/genl_json.c
+++ b/genl_json.c
@@ -33,16 +33,18 @@ struct nla_policy_json {
 
 static void sanitize_string(const char *str)
 {
-       while (*str) {
-               if (*str == '"' || *str == '\\') {
+       const unsigned char *c = (const unsigned char *)str;
+
+       while (*c) {
+               if (*c == '"' || *c == '\\') {
                        putchar('\\');
-                       putchar(*str);
-               } else if (!isprint(*str)) {
-                       printf("\\x%02x", *str);
+                       putchar(*c);
+               } else if (!isprint(*c)) {
+                       printf("\\x%02x", *c);
                } else {
-                       putchar(*str);
+                       putchar(*c);
                }
-               str++;
+               c++;
        }
 }
 

-- 
2.47.3

Reply via email to