xlat: handle NULL str in print_xlat_ex
authorEugene Syromyatnikov <evgsyr@gmail.com>
Wed, 4 Apr 2018 11:29:58 +0000 (13:29 +0200)
committerDmitry V. Levin <ldv@altlinux.org>
Fri, 27 Apr 2018 00:56:25 +0000 (00:56 +0000)
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 <ldv@altlinux.org>
xlat.c

diff --git a/xlat.c b/xlat.c
index 2156b178ac46e4116c78bc6b4c5eccc0c316b047..d52d1b10887b104ec0649710f81ca96d6f36bf76 100644 (file)
--- 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;