Skip to content

Commit

Permalink
Cast to correct types for comparisons.
Browse files Browse the repository at this point in the history
Fixes compiler errors like the following with clang-12:

/path/to/libheif/libheif/api/libheif/heif.cc:1673:10: error: result of comparison of constant 4294967295 with expression of type 'uint16_t' (aka 'unsigned short') is always false [-Werror,-Wtautological-constant-out-of-range-compare]
      cp > std::numeric_limits<std::underlying_type<heif_color_primaries>::type>::max()) {
      ~~ ^ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/path/to/libheif/libheif/api/libheif/heif.cc:1714:10: error: result of comparison of constant 4294967295 with expression of type 'uint16_t' (aka 'unsigned short') is always false [-Werror,-Wtautological-constant-out-of-range-compare]
      tc > std::numeric_limits<std::underlying_type<heif_transfer_characteristics>::type>::max()) {
      ~~ ^ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/path/to/libheif/libheif/api/libheif/heif.cc:1751:10: error: result of comparison of constant 4294967295 with expression of type 'uint16_t' (aka 'unsigned short') is always false [-Werror,-Wtautological-constant-out-of-range-compare]
      mc > std::numeric_limits<std::underlying_type<heif_matrix_coefficients>::type>::max()) {
      ~~ ^ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
3 errors generated.
  • Loading branch information
fancycode committed Jul 1, 2024
1 parent 0442780 commit f005891
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions libheif/api/libheif/heif.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1669,8 +1669,8 @@ static const std::set<typename std::underlying_type<heif_color_primaries>::type>

struct heif_error heif_nclx_color_profile_set_color_primaries(heif_color_profile_nclx* nclx, uint16_t cp)
{
if (cp < std::numeric_limits<std::underlying_type<heif_color_primaries>::type>::min() ||
cp > std::numeric_limits<std::underlying_type<heif_color_primaries>::type>::max()) {
if (static_cast<std::underlying_type<heif_color_primaries>::type>(cp) < std::numeric_limits<std::underlying_type<heif_color_primaries>::type>::min() ||
static_cast<std::underlying_type<heif_color_primaries>::type>(cp) > std::numeric_limits<std::underlying_type<heif_color_primaries>::type>::max()) {
return Error(heif_error_Invalid_input, heif_suberror_Unknown_NCLX_color_primaries).error_struct(nullptr);
}

Expand Down Expand Up @@ -1710,8 +1710,8 @@ static const std::set<typename std::underlying_type<heif_transfer_characteristic

struct heif_error heif_nclx_color_profile_set_transfer_characteristics(struct heif_color_profile_nclx* nclx, uint16_t tc)
{
if (tc < std::numeric_limits<std::underlying_type<heif_transfer_characteristics>::type>::min() ||
tc > std::numeric_limits<std::underlying_type<heif_transfer_characteristics>::type>::max()) {
if (static_cast<std::underlying_type<heif_color_primaries>::type>(tc) < std::numeric_limits<std::underlying_type<heif_transfer_characteristics>::type>::min() ||
static_cast<std::underlying_type<heif_color_primaries>::type>(tc) > std::numeric_limits<std::underlying_type<heif_transfer_characteristics>::type>::max()) {
return Error(heif_error_Invalid_input, heif_suberror_Unknown_NCLX_transfer_characteristics).error_struct(nullptr);
}

Expand Down Expand Up @@ -1747,8 +1747,8 @@ static const std::set<typename std::underlying_type<heif_matrix_coefficients>::t

struct heif_error heif_nclx_color_profile_set_matrix_coefficients(struct heif_color_profile_nclx* nclx, uint16_t mc)
{
if (mc < std::numeric_limits<std::underlying_type<heif_matrix_coefficients>::type>::min() ||
mc > std::numeric_limits<std::underlying_type<heif_matrix_coefficients>::type>::max()) {
if (static_cast<std::underlying_type<heif_color_primaries>::type>(mc) < std::numeric_limits<std::underlying_type<heif_matrix_coefficients>::type>::min() ||
static_cast<std::underlying_type<heif_color_primaries>::type>(mc) > std::numeric_limits<std::underlying_type<heif_matrix_coefficients>::type>::max()) {
return Error(heif_error_Invalid_input, heif_suberror_Unknown_NCLX_matrix_coefficients).error_struct(nullptr);
}

Expand Down

0 comments on commit f005891

Please sign in to comment.