Warning in OptimizeHuffmanForRle with gcc 7
michaelforney opened this issue · 0 comments
michaelforney commented
When building with gcc 7, OptimizeHuffmanForRle
produces the following warning:
src/zopfli/deflate.c: In function ‘OptimizeHuffmanForRle’:
src/zopfli/deflate.c:452:16: warning: argument 1 value ‘18446744073709551612’ exceeds maximum object size 9223372036854775807 [-Walloc-size-larger-than=]
good_for_rle = (int*)malloc(length * sizeof(int));
~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
In file included from src/zopfli/lz77.h:28:0,
from src/zopfli/deflate.h:28,
from src/zopfli/deflate.c:20:
/usr/include/stdlib.h:424:14: note: in a call to allocation function ‘malloc’ declared here
extern void *malloc (size_t __size) __THROW __attribute_malloc__ __wur;
This is also reported in madler/pigz#52, which uses zopfli for its highest compression level.
The warning is not present in gcc 6 or 8, so is probably just gcc 7 being confused, but I noticed that it goes away if the loop is restructured as
for (; length > 0; --length) {
if (counts[length - 1] != 0) {
/* Now counts[0..length - 1] does not have trailing zeros. */
break;
}
}
if (length == 0) {
return;
}
The OptimizeHuffmanForRle
function should also probably be made static
.