Don't printf NULL strings Signed-off-by: Ran Benita <ran234@gmail.com>
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58
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);
}