From 08a7cd132311f5b98c30657af1dc6d72ec8f0a50 Mon Sep 17 00:00:00 2001 From: Lode Date: Sat, 18 Jun 2022 16:43:31 +0200 Subject: small fixes --- lodepng.cpp | 9 +++++---- lodepng_unittest.cpp | 1 + 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/lodepng.cpp b/lodepng.cpp index 3cc0160..c2305a0 100644 --- a/lodepng.cpp +++ b/lodepng.cpp @@ -711,10 +711,11 @@ static unsigned HuffmanTree_makeTable(HuffmanTree* tree) { numpresent = 0; for(i = 0; i < tree->numcodes; ++i) { unsigned l = tree->lengths[i]; + unsigned symbol, reverse; if(l == 0) continue; - unsigned symbol = tree->codes[i]; /*the huffman bit pattern. i itself is the value.*/ + symbol = tree->codes[i]; /*the huffman bit pattern. i itself is the value.*/ /*reverse bits, because the huffman bits are given in MSB first order but the bit reader reads LSB first*/ - unsigned reverse = reverseBits(symbol, l); + reverse = reverseBits(symbol, l); numpresent++; if(l <= FIRSTBITS) { @@ -1367,8 +1368,8 @@ static unsigned inflateNoCompression(ucvector* out, LodePNGBitReader* reader, /*read the literal data: LEN bytes are now stored in the out buffer*/ if(bytepos + LEN > size) return 23; /*error: reading outside of in buffer*/ - /*out->data can be NULL (when LEN is zero), and arithmetics on NULL ptr is undefined. so we check*/ - if (out->data) { + /*out->data can be NULL (when LEN is zero), and arithmetics on NULL ptr is undefined*/ + if (LEN) { lodepng_memcpy(out->data + out->size - LEN, reader->data + bytepos, LEN); bytepos += LEN; } diff --git a/lodepng_unittest.cpp b/lodepng_unittest.cpp index a742e05..13a4e69 100644 --- a/lodepng_unittest.cpp +++ b/lodepng_unittest.cpp @@ -65,6 +65,7 @@ g++ lodepng.cpp lodepng_util.cpp pngdetail.cpp -Werror -W -Wall -ansi -pedantic ./pngdetail testdata/PngSuite/basi0g01.png *) Test compiling with some code sections with #defines disabled, for unused static function warnings etc... +g++ lodepng.cpp -W -Wall -ansi -pedantic -O3 -c -DLODEPNG_NO_COMPILE_CRC g++ lodepng.cpp -W -Wall -ansi -pedantic -O3 -c -DLODEPNG_NO_COMPILE_ZLIB g++ lodepng.cpp -W -Wall -ansi -pedantic -O3 -c -DLODEPNG_NO_COMPILE_PNG g++ lodepng.cpp -W -Wall -ansi -pedantic -O3 -c -DLODEPNG_NO_COMPILE_DECODER -- cgit v1.2.3