decoder->image can't be NULL after decoder has run
decoder->image is set to NULL only in avifDecoderCleanup(), which is
only called in avifDecoderDestroy() and at the beginning of
avifDecoderParse(). Therefore, after decoder->image is allocated in
avifDecoderParse(), decoder->image cannot be NULL.
In avif.h, instead of saying when decoder->image "can be NULL", say when
decoder->image "is invalid".
diff --git a/include/avif/avif.h b/include/avif/avif.h
index 368fa37..aafaa5f 100644
--- a/include/avif/avif.h
+++ b/include/avif/avif.h
@@ -544,7 +544,7 @@
// Set this via avifDecoderSetSource().
avifDecoderSource requestedSource;
- // The current decoded image, owned by the decoder. Can be NULL if the decoder hasn't run or has run
+ // The current decoded image, owned by the decoder. Is invalid if the decoder hasn't run or has run
// out of images. The YUV and A contents of this image are likely owned by the decoder, so be
// sure to copy any data inside of this image before advancing to the next image or reusing the
// decoder. It is legal to call avifImageYUVToRGB() on this in between calls to avifDecoderNextImage(),
diff --git a/src/read.c b/src/read.c
index 04b131a..e7d024d 100644
--- a/src/read.c
+++ b/src/read.c
@@ -2388,9 +2388,6 @@
if (result != AVIF_RESULT_OK) {
return result;
}
- if (!decoder->image) {
- return AVIF_RESULT_NO_IMAGES_REMAINING;
- }
avifImageCopy(image, decoder->image);
return AVIF_RESULT_OK;
}