From 9b7b68479b476ed30101e8be33eb502cd4f82e41 Mon Sep 17 00:00:00 2001 From: Wan-Teh Chang Date: Wed, 7 Feb 2024 15:02:01 -0800 Subject: [PATCH] Print unprintable item->type in diagnostic message In avifDecoderGenerateImageGridTiles(), replace unprintable characters in item->type with '.' and also print the hex values of item->type in parentheses. For example, if item->type is four NUL characters ('\0'), avifdec prints the following diagnostic message: Before: Diagnostics: * Tile item ID 5 has an unknown item type '' After: Diagnostics: * Tile item ID 5 has an unknown item type '....' (0000 0000) --- src/read.c | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/src/read.c b/src/read.c index f09855c6de..1737f45da8 100644 --- a/src/read.c +++ b/src/read.c @@ -4,6 +4,7 @@ #include "avif/internal.h" #include +#include #include #include #include @@ -1421,7 +1422,22 @@ static avifResult avifDecoderGenerateImageGridTiles(avifDecoder * decoder, avifI // as errors. const avifCodecType tileCodecType = avifGetCodecType(item->type); if (tileCodecType == AVIF_CODEC_TYPE_UNKNOWN) { - avifDiagnosticsPrintf(&decoder->diag, "Tile item ID %u has an unknown item type '%.4s'", item->id, (const char *)item->type); + char type[4]; + for (int j = 0; j < 4; j++) { + if (isprint((unsigned char)item->type[j])) { + type[j] = item->type[j]; + } else { + type[j] = '.'; + } + } + avifDiagnosticsPrintf(&decoder->diag, + "Tile item ID %u has an unknown item type '%.4s' (%02x%02x %02x%02x)", + item->id, + type, + item->type[0], + item->type[1], + item->type[2], + item->type[3]); return AVIF_RESULT_INVALID_IMAGE_GRID; }