From b5962b25ae3ec1ac54765203f009674608d8fcb1 Mon Sep 17 00:00:00 2001 From: Greg Kennedy Date: Fri, 10 Mar 2023 20:09:01 -0600 Subject: [PATCH] Fix compilation on MSVC 2008 Misc. linting to get this building on my machine - an undefined function (found in io.h) and some casts required to avoid warnings or ambiguous statements when compiling in C++ mode. --- src/zopfli/tree.c | 4 ++-- src/zopfli/util.h | 2 +- src/zopfli/zopfli_bin.c | 1 + 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/src/zopfli/tree.c b/src/zopfli/tree.c index c4575119..bb13ab60 100644 --- a/src/zopfli/tree.c +++ b/src/zopfli/tree.c @@ -76,13 +76,13 @@ void ZopfliCalculateEntropy(const size_t* count, size_t n, double* bitlengths) { for (i = 0; i < n; ++i) { sum += count[i]; } - log2sum = (sum == 0 ? log(n) : log(sum)) * kInvLog2; + log2sum = (sum == 0 ? log((double)n) : log((double)sum)) * kInvLog2; for (i = 0; i < n; ++i) { /* When the count of the symbol is 0, but its cost is requested anyway, it means the symbol will appear at least once anyway, so give it the cost as if its count is 1.*/ if (count[i] == 0) bitlengths[i] = log2sum; - else bitlengths[i] = log2sum - log(count[i]) * kInvLog2; + else bitlengths[i] = log2sum - log((double)count[i]) * kInvLog2; /* Depending on compiler and architecture, the above subtraction of two floating point numbers may give a negative result very close to zero instead of zero (e.g. -5.973954e-17 with gcc 4.1.2 on Ubuntu 11.4). Clamp diff --git a/src/zopfli/util.h b/src/zopfli/util.h index 4b73504f..d1693d1b 100644 --- a/src/zopfli/util.h +++ b/src/zopfli/util.h @@ -62,7 +62,7 @@ Set it to 0 to disable master blocks. /* Used to initialize costs for example */ -#define ZOPFLI_LARGE_FLOAT 1e30 +#define ZOPFLI_LARGE_FLOAT 1e30f /* For longest match cache. max 256. Uses huge amounts of memory but makes it diff --git a/src/zopfli/zopfli_bin.c b/src/zopfli/zopfli_bin.c index a42badef..3fb3cc51 100644 --- a/src/zopfli/zopfli_bin.c +++ b/src/zopfli/zopfli_bin.c @@ -35,6 +35,7 @@ decompressor. /* Windows workaround for stdout output. */ #if _WIN32 +#include #include #endif