The underlying integer type of an enumeration is implementation-defined (see C11, 6.7.2.2 (4)); GCC defaults to unsigned if there are no negative values like for all enums from pixfmt.h except enum AVPixelFormat. This means that tests like "if (csp >= AVCOL_SPC_NB)" for invalid colorspaces need not work as expected (namely if enum AVColorSpace is signed). It also means that testing for such an enum variable to be >= 0 may be tautologically true. Clang emits a -Wtautological-unsigned-enum-zero-compare warning for this. Fix both of these issues by casting to unsigned. Also do the same in libswscale/format.c.
Unified · Split
| @@ -59,7 +59,7 @@ const struct AVLumaCoefficients *av_csp_luma_coeffs_from_avcsp(enum AVColorSpace · 58 unmodified lines | ||
| 59 | 59 | { |
| 60 | 60 | const AVLumaCoefficients *coeffs; |
| 61 | 61 | |
| 62 | − if (csp >= AVCOL_SPC_NB) | |
| 62 | + if ((unsigned)csp >= AVCOL_SPC_NB) | |
| 63 | 63 | return NULL; |
| 64 | 64 | coeffs = &luma_coefficients[csp]; |
| 65 | 65 | if (!coeffs->cr.num) |
| @@ -91,7 +91,7 @@ const AVColorPrimariesDesc *av_csp_primaries_desc_from_id(enum AVColorPrimaries · 25 unmodified lines | ||
| 91 | 91 | { |
| 92 | 92 | const AVColorPrimariesDesc *p; |
| 93 | 93 | |
| 94 | − if (prm >= AVCOL_PRI_NB) | |
| 94 | + if ((unsigned)prm >= AVCOL_PRI_NB) | |
| 95 | 95 | return NULL; |
| 96 | 96 | p = &color_primaries[prm]; |
| 97 | 97 | if (!p->prim.r.x.num) |
| @@ -149,7 +149,7 @@ static const double approximate_gamma[AVCOL_TRC_NB] = { · 51 unmodified lines | ||
| 149 | 149 | double av_csp_approximate_trc_gamma(enum AVColorTransferCharacteristic trc) |
| 150 | 150 | { |
| 151 | 151 | double gamma; |
| 152 | − if (trc >= AVCOL_TRC_NB) | |
| 152 | + if ((unsigned)trc >= AVCOL_TRC_NB) | |
| 153 | 153 | return 0.0; |
| 154 | 154 | gamma = approximate_gamma[trc]; |
| 155 | 155 | if (gamma > 0) |
| @@ -399,7 +399,7 @@ static const av_csp_trc_function trc_funcs[AVCOL_TRC_NB] = { · 243 unmodified lines | ||
| 399 | 399 | |
| 400 | 400 | av_csp_trc_function av_csp_trc_func_from_id(enum AVColorTransferCharacteristic trc) |
| 401 | 401 | { |
| 402 | − if (trc >= AVCOL_TRC_NB) | |
| 402 | + if ((unsigned)trc >= AVCOL_TRC_NB) | |
| 403 | 403 | return NULL; |
| 404 | 404 | return trc_funcs[trc]; |
| 405 | 405 | } |
| @@ -425,7 +425,7 @@ static const av_csp_trc_function trc_inv_funcs[AVCOL_TRC_NB] = { · 19 unmodified lines | ||
| 425 | 425 | |
| 426 | 426 | av_csp_trc_function av_csp_trc_func_inv_from_id(enum AVColorTransferCharacteristic trc) |
| 427 | 427 | { |
| 428 | − if (trc >= AVCOL_TRC_NB) | |
| 428 | + if ((unsigned)trc >= AVCOL_TRC_NB) | |
| 429 | 429 | return NULL; |
| 430 | 430 | return trc_inv_funcs[trc]; |
| 431 | 431 | } |
| @@ -604,7 +604,7 @@ static const av_csp_eotf_function eotf_funcs[AVCOL_TRC_NB] = { · 172 unmodified lines | ||
| 604 | 604 | |
| 605 | 605 | av_csp_eotf_function av_csp_itu_eotf(enum AVColorTransferCharacteristic trc) |
| 606 | 606 | { |
| 607 | − if (trc < 0 || trc >= AVCOL_TRC_NB) | |
| 607 | + if ((unsigned)trc >= AVCOL_TRC_NB) | |
| 608 | 608 | return NULL; |
| 609 | 609 | return eotf_funcs[trc]; |
| 610 | 610 | } |
| @@ -630,7 +630,7 @@ static const av_csp_eotf_function eotf_inv_funcs[AVCOL_TRC_NB] = { · 19 unmodified lines | ||
| 630 | 630 | |
| 631 | 631 | av_csp_eotf_function av_csp_itu_eotf_inv(enum AVColorTransferCharacteristic trc) |
| 632 | 632 | { |
| 633 | − if (trc < 0 || trc >= AVCOL_TRC_NB) | |
| 633 | + if ((unsigned)trc >= AVCOL_TRC_NB) | |
| 634 | 634 | return NULL; |
| 635 | 635 | return eotf_inv_funcs[trc]; |
| 636 | 636 | } |
| @@ -537,12 +537,12 @@ int sws_test_transfer(enum AVColorTransferCharacteristic trc, int output) · 536 unmodified lines | ||
| 537 | 537 | |
| 538 | 538 | static int test_range(enum AVColorRange range) |
| 539 | 539 | { |
| 540 | − return range >= 0 && range < AVCOL_RANGE_NB; | |
| 540 | + return (unsigned)range < AVCOL_RANGE_NB; | |
| 541 | 541 | } |
| 542 | 542 | |
| 543 | 543 | static int test_loc(enum AVChromaLocation loc) |
| 544 | 544 | { |
| 545 | − return loc >= 0 && loc < AVCHROMA_LOC_NB; | |
| 545 | + return (unsigned)loc < AVCHROMA_LOC_NB; | |
| 546 | 546 | } |
| 547 | 547 | |
| 548 | 548 | int ff_test_fmt(const SwsFormat *fmt, int output) |