Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 14 additions & 2 deletions .github/workflows/ci-c-warnings.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}

Expand Down Expand Up @@ -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 <stdint.h>/#include <stdint.h>\n#include <stdbool.h>/' 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
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we also need this alternative definition? Does stdbool not catch all the bugs?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nope, cf the other PR: both found different bugs .....

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
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suggest we add these two alternative definitions of avifBool to avif.h and avoid patching avif.h like this. The alternative definitions would be guarded by macros that we define in this CI workflow.

If we want to patch avif.h, we may want to add comments around the definition of avifBool to prevent people form changing or even reformatting it.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think adding two guards (for stdbool and enum) is a lot of noise for a public header no? Especially just for a CI usage (not even a test).


- name: Prepare libavif (cmake)
run: >
Expand Down
2 changes: 1 addition & 1 deletion apps/avifdec.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
6 changes: 6 additions & 0 deletions include/avif/internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -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

// ---------------------------------------------------------------------------
Expand Down
6 changes: 3 additions & 3 deletions src/read.c
Original file line number Diff line number Diff line change
Expand Up @@ -3984,15 +3984,15 @@ 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;
}

static avifProperty * avifDecoderItemAddProperty(avifDecoderItem * item, const avifProperty * metaProperty)
{
avifProperty * itemProperty = avifArrayPush(&item->properties);
AVIF_CHECK(itemProperty);
AVIF_CHECKERR(itemProperty, NULL);
*itemProperty = *metaProperty;
return itemProperty;
}
Expand Down Expand Up @@ -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;
Expand Down
4 changes: 2 additions & 2 deletions src/write.c
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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) {
Expand Down
Loading