Compile with Clang -Wshorten-64-to-32 warning flag
Unfortunately, this does not warn about the conversion from
'const uint64_t' to 'int' that MSVC warns about, which is fixed in
https://github.com/AOMediaCodec/libavif/pull/1036.
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 93b7dea..4637173 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -125,7 +125,7 @@
include(CheckCCompilerFlag)
if(CMAKE_C_COMPILER_ID MATCHES "Clang")
message(STATUS "libavif: Enabling warnings for Clang")
- add_definitions(-Wall -Wextra)
+ add_definitions(-Wall -Wextra -Wshorten-64-to-32)
elseif(CMAKE_C_COMPILER_ID MATCHES "GNU")
message(STATUS "libavif: Enabling warnings for GCC")
add_definitions(-Wall -Wextra)
diff --git a/apps/avifdec.c b/apps/avifdec.c
index ba67d2e..6081e92 100644
--- a/apps/avifdec.c
+++ b/apps/avifdec.c
@@ -159,11 +159,12 @@
ignoreICC = AVIF_TRUE;
} else if (!strcmp(arg, "--size-limit")) {
NEXTARG();
- imageSizeLimit = strtoul(arg, NULL, 10);
- if ((imageSizeLimit > AVIF_DEFAULT_IMAGE_SIZE_LIMIT) || (imageSizeLimit == 0)) {
+ unsigned long value = strtoul(arg, NULL, 10);
+ if ((value > AVIF_DEFAULT_IMAGE_SIZE_LIMIT) || (value == 0)) {
fprintf(stderr, "ERROR: invalid image size limit: %s\n", arg);
return 1;
}
+ imageSizeLimit = (uint32_t)value;
} else {
// Positional argument
if (!inputFilename) {
diff --git a/tests/gtest/avifincrtest_helpers.cc b/tests/gtest/avifincrtest_helpers.cc
index 889059a..a61d3d3 100644
--- a/tests/gtest/avifincrtest_helpers.cc
+++ b/tests/gtest/avifincrtest_helpers.cc
@@ -100,8 +100,8 @@
byte_count -= byte_count / 2;
}
// Linearly map the input availability ratio to the decoded row ratio.
- const uint32_t min_decoded_cell_row_count =
- (height / cell_height) * available_byte_count / byte_count;
+ const uint32_t min_decoded_cell_row_count = static_cast<uint32_t>(
+ (height / cell_height) * available_byte_count / byte_count);
const uint32_t min_decoded_px_row_count =
min_decoded_cell_row_count * cell_height;
// One cell is the incremental decoding granularity.