Skip to content

Commit

Permalink
Print unprintable item->type in diagnostic message
Browse files Browse the repository at this point in the history
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)
  • Loading branch information
wantehchang committed Feb 7, 2024
1 parent 0bcc007 commit 9b7b684
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion src/read.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include "avif/internal.h"

#include <assert.h>
#include <ctype.h>
#include <inttypes.h>
#include <limits.h>
#include <math.h>
Expand Down Expand Up @@ -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;
}

Expand Down

0 comments on commit 9b7b684

Please sign in to comment.