Commit 300f3fb1e051e4705a3d7787d508c10af98e4bb4

Ran Benita 2012-08-29T10:12:56

Don't printf NULL strings Signed-off-by: Ran Benita <ran234@gmail.com>

diff --git a/src/utils.h b/src/utils.h
index 4b2bb32..a3bd5d4 100644
--- a/src/utils.h
+++ b/src/utils.h
@@ -75,6 +75,12 @@ isempty(const char *s)
     return s == NULL || s[0] == '\0';
 }
 
+static inline const char *
+strnull(const char *s)
+{
+    return s ? s : "(null)";
+}
+
 #define MIN(a, b) ((a) < (b) ? (a) : (b))
 #define MAX(a, b) ((a) > (b) ? (a) : (b))
 
diff --git a/src/xkbcomp/xkbcomp.c b/src/xkbcomp/xkbcomp.c
index b258880..7befd98 100644
--- a/src/xkbcomp/xkbcomp.c
+++ b/src/xkbcomp/xkbcomp.c
@@ -75,16 +75,18 @@ xkb_map_new_from_names(struct xkb_context *ctx,
     log_dbg(ctx,
             "Compiling from RMLVO: rules '%s', model '%s', layout '%s', "
             "variant '%s', options '%s'\n",
-            rmlvo.rules, rmlvo.model, rmlvo.layout, rmlvo.variant,
-            rmlvo.options);
+            strnull(rmlvo.rules), strnull(rmlvo.model),
+            strnull(rmlvo.layout), strnull(rmlvo.variant),
+            strnull(rmlvo.options));
 
     ok = xkb_components_from_rules(ctx, &rmlvo, &kccgst);
     if (!ok) {
         log_err(ctx,
                 "Couldn't look up rules '%s', model '%s', layout '%s', "
                 "variant '%s', options '%s'\n",
-                rmlvo.rules, rmlvo.model, rmlvo.layout, rmlvo.variant,
-                rmlvo.options);
+                strnull(rmlvo.rules), strnull(rmlvo.model),
+                strnull(rmlvo.layout), strnull(rmlvo.variant),
+                strnull(rmlvo.options));
         return NULL;
     }
 
diff --git a/test/rulescomp.c b/test/rulescomp.c
index 0d40761..1dbfeb0 100644
--- a/test/rulescomp.c
+++ b/test/rulescomp.c
@@ -44,7 +44,8 @@ test_rmlvo(struct xkb_context *context, const char *rules,
                                 options);
     if (keymap) {
         fprintf(stderr, "Compiled '%s' '%s' '%s' '%s' '%s'\n",
-                rules, model, layout, variant, options);
+                strnull(rules), strnull(model), strnull(layout),
+                strnull(variant), strnull(options));
         xkb_map_unref(keymap);
     }