From 69b958656e22c8b3fdb4f4ea3e07a7b5cd608d3d Mon Sep 17 00:00:00 2001 From: Eugene Syromyatnikov Date: Wed, 4 Apr 2018 13:29:58 +0200 Subject: [PATCH] xlat: handle NULL str in print_xlat_ex It allows to use the following code pattern: print_xlat_ex(val, xlookup(xlat, val), XLAT_STYLE_FMT_D); * xlat.c (print_xlat_ex): Handle str being NULL: print val instead. Co-Authored-by: Dmitry V. Levin --- xlat.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/xlat.c b/xlat.c index 2156b178..d52d1b10 100644 --- a/xlat.c +++ b/xlat.c @@ -400,14 +400,17 @@ print_xlat_ex(const uint64_t val, const char *str, enum xlat_style style) style = get_xlat_style(style); switch (xlat_verbose(style)) { + case XLAT_STYLE_ABBREV: + if (str) { + tprints(str); + break; + } + ATTRIBUTE_FALLTHROUGH; + case XLAT_STYLE_RAW: print_xlat_val(val, style); break; - case XLAT_STYLE_ABBREV: - tprints(str); - break; - default: error_func_msg("Unexpected style value of %#x", style); ATTRIBUTE_FALLTHROUGH; -- 2.50.1