Skip to content

Commit a5a18f8

Browse files
committed
Add AVIF_ASSERT_NOT_REACHED_OR_RETURN macro
1 parent 8b7f968 commit a5a18f8

File tree

4 files changed

+10
-4
lines changed

4 files changed

+10
-4
lines changed

apps/avifdec.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -359,7 +359,7 @@ int main(int argc, char * argv[])
359359

360360
const avifBool decodeAllFrames = frameIndex == DECODE_ALL_FRAMES;
361361
int currIndex = decodeAllFrames ? 0 : frameIndex;
362-
while (AVIF_TRUE) {
362+
for (;;) {
363363
result = decodeAllFrames ? avifDecoderNextImage(decoder) : avifDecoderNthImage(decoder, frameIndex);
364364
if (result != AVIF_RESULT_OK) {
365365
break;

include/avif/internal.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,14 @@ static inline void avifBreakOnError()
6262
// AVIF_ASSERT_OR_RETURN() can be used instead of assert() for extra security in release builds.
6363
#ifdef NDEBUG
6464
#define AVIF_ASSERT_OR_RETURN(A) AVIF_CHECKERR((A), AVIF_RESULT_INTERNAL_ERROR)
65+
#define AVIF_ASSERT_NOT_REACHED_OR_RETURN \
66+
do { \
67+
avifBreakOnError(); \
68+
return AVIF_RESULT_INTERNAL_ERROR; \
69+
} while (0)
6570
#else
6671
#define AVIF_ASSERT_OR_RETURN(A) assert(A)
72+
#define AVIF_ASSERT_NOT_REACHED_OR_RETURN assert(AVIF_FALSE);
6773
#endif
6874

6975
// ---------------------------------------------------------------------------

src/read.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5479,7 +5479,7 @@ static avifResult avifMetaFindAlphaItem(avifMeta * meta,
54795479
for (uint32_t dimgIdx = 0; dimgIdx < tileCount; ++dimgIdx) {
54805480
if (dimgIdxToAlphaItemIdx[dimgIdx] >= meta->items.count) {
54815481
avifFree(dimgIdxToAlphaItemIdx);
5482-
AVIF_ASSERT_OR_RETURN(AVIF_FALSE);
5482+
AVIF_ASSERT_NOT_REACHED_OR_RETURN;
54835483
}
54845484
avifDecoderItem * alphaTileItem = meta->items.item[dimgIdxToAlphaItemIdx[dimgIdx]];
54855485
alphaTileItem->dimgForID = (*alphaItem)->id;

src/write.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2673,7 +2673,7 @@ static avifResult avifEncoderWriteMiniBox(avifEncoder * encoder, avifRWStream *
26732673

26742674
if (floatFlag) {
26752675
// bit(2) bit_depth_log2_minus4;
2676-
AVIF_ASSERT_OR_RETURN(AVIF_FALSE);
2676+
AVIF_ASSERT_NOT_REACHED_OR_RETURN;
26772677
} else {
26782678
AVIF_CHECKRES(avifRWStreamWriteBits(s, image->depth > 8, 1)); // bit(1) high_bit_depth_flag;
26792679
if (image->depth > 8) {
@@ -2741,7 +2741,7 @@ static avifResult avifEncoderWriteMiniBox(avifEncoder * encoder, avifRWStream *
27412741
AVIF_CHECKRES(avifRWStreamWriteBits(s, gainmapFloatFlag, 1)); // bit(1) gainmap_float_flag;
27422742
if (gainmapFloatFlag) {
27432743
// bit(2) gainmap_bit_depth_log2_minus4;
2744-
AVIF_ASSERT_OR_RETURN(AVIF_FALSE);
2744+
AVIF_ASSERT_NOT_REACHED_OR_RETURN;
27452745
} else {
27462746
AVIF_CHECKRES(avifRWStreamWriteBits(s, gainmap->depth > 8, 1)); // bit(1) gainmap_high_bit_depth_flag;
27472747
if (gainmap->depth > 8) {

0 commit comments

Comments
 (0)