diff --git a/.github/workflows/ci-c-warnings.yml b/.github/workflows/ci-c-warnings.yml index 81380569ff..47ef787de9 100644 --- a/.github/workflows/ci-c-warnings.yml +++ b/.github/workflows/ci-c-warnings.yml @@ -16,10 +16,10 @@ jobs: strategy: fail-fast: false # Generate the configurations: - # case 0: nodiscard + # case 0: nodiscard, case 1: use stdbool, case 2: use enums matrix: os: [ubuntu-latest, windows-latest] - case: [0] + case: [0, 1, 2] runs-on: ${{ matrix.os }} @@ -53,6 +53,18 @@ jobs: - name: Enable nodiscard if: ${{ matrix.case == 0}} run: echo "CMAKE_AVIF_FLAGS=\"-DAVIF_ENABLE_NODISCARD=ON\"" >> $GITHUB_ENV + - name: Use stdbool for AVIF_TRUE/AVIF_FALSE + if: ${{ matrix.case == 1}} + run: | + sed -i 's/#include /#include \n#include /' include/avif/avif.h + sed -i 's/typedef int avifBool;/typedef bool avifBool;/' include/avif/avif.h + sed -i 's/#define AVIF_TRUE 1/#define AVIF_TRUE true/' include/avif/avif.h + sed -i 's/#define AVIF_FALSE 0/#define AVIF_FALSE false/' include/avif/avif.h + - name: Use enums for AVIF_TRUE/AVIF_FALSE + if: ${{ matrix.case == 2}} + run: | + sed -i 's/#define AVIF_TRUE 1/enum avifTrueFalse_{ AVIF_TRUE = 1,/' include/avif/avif.h + sed -i 's/#define AVIF_FALSE 0/AVIF_FALSE = 0};/' include/avif/avif.h - name: Prepare libavif (cmake) run: > diff --git a/apps/avifdec.c b/apps/avifdec.c index f30a90cb11..d937aebfe0 100644 --- a/apps/avifdec.c +++ b/apps/avifdec.c @@ -359,7 +359,7 @@ int main(int argc, char * argv[]) const avifBool decodeAllFrames = frameIndex == DECODE_ALL_FRAMES; int currIndex = decodeAllFrames ? 0 : frameIndex; - while (AVIF_TRUE) { + for (;;) { result = decodeAllFrames ? avifDecoderNextImage(decoder) : avifDecoderNthImage(decoder, frameIndex); if (result != AVIF_RESULT_OK) { break; diff --git a/include/avif/internal.h b/include/avif/internal.h index 4e93c438a9..1ffb9a4025 100644 --- a/include/avif/internal.h +++ b/include/avif/internal.h @@ -62,8 +62,14 @@ static inline void avifBreakOnError() // AVIF_ASSERT_OR_RETURN() can be used instead of assert() for extra security in release builds. #ifdef NDEBUG #define AVIF_ASSERT_OR_RETURN(A) AVIF_CHECKERR((A), AVIF_RESULT_INTERNAL_ERROR) +#define AVIF_ASSERT_NOT_REACHED_OR_RETURN \ + do { \ + avifBreakOnError(); \ + return AVIF_RESULT_INTERNAL_ERROR; \ + } while (0) #else #define AVIF_ASSERT_OR_RETURN(A) assert(A) +#define AVIF_ASSERT_NOT_REACHED_OR_RETURN assert(0); #endif // --------------------------------------------------------------------------- diff --git a/src/read.c b/src/read.c index e930658ffe..9510a58d92 100644 --- a/src/read.c +++ b/src/read.c @@ -3984,7 +3984,7 @@ static avifResult avifParseMovieBox(avifDecoderData * data, static avifProperty * avifMetaCreateProperty(avifMeta * meta, const char * propertyType) { avifProperty * metaProperty = avifArrayPush(&meta->properties); - AVIF_CHECK(metaProperty); + AVIF_CHECKERR(metaProperty, NULL); memcpy(metaProperty->type, propertyType, 4); return metaProperty; } @@ -3992,7 +3992,7 @@ static avifProperty * avifMetaCreateProperty(avifMeta * meta, const char * prope static avifProperty * avifDecoderItemAddProperty(avifDecoderItem * item, const avifProperty * metaProperty) { avifProperty * itemProperty = avifArrayPush(&item->properties); - AVIF_CHECK(itemProperty); + AVIF_CHECKERR(itemProperty, NULL); *itemProperty = *metaProperty; return itemProperty; } @@ -5479,7 +5479,7 @@ static avifResult avifMetaFindAlphaItem(avifMeta * meta, for (uint32_t dimgIdx = 0; dimgIdx < tileCount; ++dimgIdx) { if (dimgIdxToAlphaItemIdx[dimgIdx] >= meta->items.count) { avifFree(dimgIdxToAlphaItemIdx); - AVIF_ASSERT_OR_RETURN(AVIF_FALSE); + AVIF_ASSERT_NOT_REACHED_OR_RETURN; } avifDecoderItem * alphaTileItem = meta->items.item[dimgIdxToAlphaItemIdx[dimgIdx]]; alphaTileItem->dimgForID = (*alphaItem)->id; diff --git a/src/write.c b/src/write.c index a4e5f012b9..9beeb2bf62 100644 --- a/src/write.c +++ b/src/write.c @@ -2678,7 +2678,7 @@ static avifResult avifEncoderWriteMiniBox(avifEncoder * encoder, avifRWStream * if (floatFlag) { // bit(2) bit_depth_log2_minus4; - AVIF_ASSERT_OR_RETURN(AVIF_FALSE); + AVIF_ASSERT_NOT_REACHED_OR_RETURN; } else { AVIF_CHECKRES(avifRWStreamWriteBits(s, image->depth > 8, 1)); // bit(1) high_bit_depth_flag; if (image->depth > 8) { @@ -2746,7 +2746,7 @@ static avifResult avifEncoderWriteMiniBox(avifEncoder * encoder, avifRWStream * AVIF_CHECKRES(avifRWStreamWriteBits(s, gainmapFloatFlag, 1)); // bit(1) gainmap_float_flag; if (gainmapFloatFlag) { // bit(2) gainmap_bit_depth_log2_minus4; - AVIF_ASSERT_OR_RETURN(AVIF_FALSE); + AVIF_ASSERT_NOT_REACHED_OR_RETURN; } else { AVIF_CHECKRES(avifRWStreamWriteBits(s, gainmap->depth > 8, 1)); // bit(1) gainmap_high_bit_depth_flag; if (gainmap->depth > 8) {