From f19612df5e2f016103fdaadc8158b51389e29ac6 Mon Sep 17 00:00:00 2001 From: Dair Grant Date: Thu, 25 Feb 2016 11:41:33 +0000 Subject: [PATCH 1/6] Fix unnecessary destructor warning with C++11. --- lodepng.h | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/lodepng.h b/lodepng.h index 9ecedd1e..b6fc556f 100644 --- a/lodepng.h +++ b/lodepng.h @@ -631,8 +631,10 @@ typedef struct LodePNGState LodePNGInfo info_png; /*info of the PNG image obtained after decoding*/ unsigned error; #ifdef LODEPNG_COMPILE_CPP - /* For the lodepng::State subclass. */ + /* For the lodepng::State subclass - produces warning on C++11. */ + #if __cplusplus < 201103L virtual ~LodePNGState(){} + #endif #endif } LodePNGState; From 43c4ac5bc5837c172022a2595a4b96892521e4e9 Mon Sep 17 00:00:00 2001 From: Dair Grant Date: Thu, 25 Feb 2016 11:42:49 +0000 Subject: [PATCH 2/6] Fix missing prototype warnings, make internal functions static. --- lodepng.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lodepng.cpp b/lodepng.cpp index 0fca1a91..82250ad0 100644 --- a/lodepng.cpp +++ b/lodepng.cpp @@ -320,7 +320,7 @@ static void string_set(char** out, const char* in) /* ////////////////////////////////////////////////////////////////////////// */ -unsigned lodepng_read32bitInt(const unsigned char* buffer) +static unsigned lodepng_read32bitInt(const unsigned char* buffer) { return (unsigned)((buffer[0] << 24) | (buffer[1] << 16) | (buffer[2] << 8) | buffer[3]); } @@ -2676,7 +2676,7 @@ size_t lodepng_get_raw_size(unsigned w, unsigned h, const LodePNGColorMode* colo return ((n / 8) * bpp) + ((n & 7) * bpp + 7) / 8; } -size_t lodepng_get_raw_size_lct(unsigned w, unsigned h, LodePNGColorType colortype, unsigned bitdepth) +static size_t lodepng_get_raw_size_lct(unsigned w, unsigned h, LodePNGColorType colortype, unsigned bitdepth) { /*will not overflow for any color type if roughly w * h < 268435455*/ int bpp = lodepng_get_bpp_lct(colortype, bitdepth); From 3ceb05962388b600a5c2123cabb6eab14d2aae35 Mon Sep 17 00:00:00 2001 From: Dair Grant Date: Thu, 25 Feb 2016 11:43:40 +0000 Subject: [PATCH 3/6] Fix unused function warning, remove unused function. --- lodepng.cpp | 7 ------- 1 file changed, 7 deletions(-) diff --git a/lodepng.cpp b/lodepng.cpp index 82250ad0..6f877871 100644 --- a/lodepng.cpp +++ b/lodepng.cpp @@ -2931,13 +2931,6 @@ unsigned lodepng_info_copy(LodePNGInfo* dest, const LodePNGInfo* source) return 0; } -void lodepng_info_swap(LodePNGInfo* a, LodePNGInfo* b) -{ - LodePNGInfo temp = *a; - *a = *b; - *b = temp; -} - /* ////////////////////////////////////////////////////////////////////////// */ /*index: bitgroup index, bits: bitgroup size(1, 2 or 4), in: bitgroup value, out: octet array to add bits to*/ From 30239d4fac574262a682c1757cedcd9644be5def Mon Sep 17 00:00:00 2001 From: Dair Grant Date: Thu, 25 Feb 2016 11:44:45 +0000 Subject: [PATCH 4/6] Fixed discarding const warning. --- lodepng.cpp | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/lodepng.cpp b/lodepng.cpp index 6f877871..dd49f7c4 100644 --- a/lodepng.cpp +++ b/lodepng.cpp @@ -383,7 +383,7 @@ unsigned lodepng_save_file(const unsigned char* buffer, size_t buffersize, const FILE* file; file = fopen(filename, "wb" ); if(!file) return 79; - fwrite((char*)buffer , 1 , buffersize, file); + fwrite((const char*)buffer , 1 , buffersize, file); fclose(file); return 0; } @@ -4303,7 +4303,7 @@ static unsigned readChunk_zTXt(LodePNGInfo* info, const LodePNGDecompressSetting length = chunkLength - string2_begin; /*will fail if zlib error, e.g. if length is too small*/ error = zlib_decompress(&decoded.data, &decoded.size, - (unsigned char*)(&data[string2_begin]), + (const unsigned char*)(&data[string2_begin]), length, zlibsettings); if(error) break; ucvector_push_back(&decoded, 0); @@ -4386,7 +4386,7 @@ static unsigned readChunk_iTXt(LodePNGInfo* info, const LodePNGDecompressSetting { /*will fail if zlib error, e.g. if length is too small*/ error = zlib_decompress(&decoded.data, &decoded.size, - (unsigned char*)(&data[begin]), + (const unsigned char*)(&data[begin]), length, zlibsettings); if(error) break; if(decoded.allocsize < decoded.size) decoded.allocsize = decoded.size; @@ -4942,7 +4942,7 @@ static unsigned addChunk_zTXt(ucvector* out, const char* keyword, const char* te ucvector_push_back(&data, 0); /*compression method: 0*/ error = zlib_compress(&compressed.data, &compressed.size, - (unsigned char*)textstring, textsize, zlibsettings); + (const unsigned char*)textstring, textsize, zlibsettings); if(!error) { for(i = 0; i != compressed.size; ++i) ucvector_push_back(&data, compressed.data[i]); @@ -4978,7 +4978,7 @@ static unsigned addChunk_iTXt(ucvector* out, unsigned compressed, const char* ke ucvector compressed_data; ucvector_init(&compressed_data); error = zlib_compress(&compressed_data.data, &compressed_data.size, - (unsigned char*)textstring, textsize, zlibsettings); + (const unsigned char*)textstring, textsize, zlibsettings); if(!error) { for(i = 0; i != compressed_data.size; ++i) ucvector_push_back(&data, compressed_data.data[i]); @@ -5955,7 +5955,7 @@ unsigned save_file(const std::vector& buffer, const std::string& { std::ofstream file(filename.c_str(), std::ios::out|std::ios::binary); if(!file) return 79; - file.write(buffer.empty() ? 0 : (char*)&buffer[0], std::streamsize(buffer.size())); + file.write(buffer.empty() ? 0 : (const char*)&buffer[0], std::streamsize(buffer.size())); return 0; } #endif /* LODEPNG_COMPILE_DISK */ From cfe89f36f88d42f90a6821b0b15ac3a8ef6b1806 Mon Sep 17 00:00:00 2001 From: Dair Grant Date: Thu, 25 Feb 2016 11:45:04 +0000 Subject: [PATCH 5/6] Fix missing default: warning. --- lodepng.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/lodepng.cpp b/lodepng.cpp index dd49f7c4..1e3d7849 100644 --- a/lodepng.cpp +++ b/lodepng.cpp @@ -2531,6 +2531,7 @@ static unsigned getNumColorChannels(LodePNGColorType colortype) case 3: return 1; /*palette*/ case 4: return 2; /*grey + alpha*/ case 6: return 4; /*RGBA*/ + default: break; } return 0; /*unexisting color type*/ } @@ -5917,6 +5918,7 @@ const char* lodepng_error_text(unsigned code) case 92: return "too many pixels, not supported"; case 93: return "zero width or height is invalid"; case 94: return "header chunk must have a size of 13 bytes"; + default: break; } return "unknown error code"; } From d4bb52993071c86147dc7a60c69c77b736db3e9a Mon Sep 17 00:00:00 2001 From: Dair Grant Date: Thu, 25 Feb 2016 11:45:51 +0000 Subject: [PATCH 6/6] Fix implicit size cast warnings on 64-bit. --- lodepng.cpp | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/lodepng.cpp b/lodepng.cpp index 1e3d7849..e6aa79b9 100644 --- a/lodepng.cpp +++ b/lodepng.cpp @@ -1419,11 +1419,11 @@ static void updateHashChain(Hash* hash, size_t wpos, unsigned hashval, unsigned { hash->val[wpos] = (int)hashval; if(hash->head[hashval] != -1) hash->chain[wpos] = hash->head[hashval]; - hash->head[hashval] = wpos; + hash->head[hashval] = (int) wpos; hash->zeros[wpos] = numzeros; if(hash->headz[numzeros] != -1) hash->chainz[wpos] = hash->headz[numzeros]; - hash->headz[numzeros] = wpos; + hash->headz[numzeros] = (int) wpos; } /* @@ -1495,7 +1495,7 @@ static unsigned encodeLZ77(uivector* out, Hash* hash, for(;;) { if(chainlength++ >= maxchainlength) break; - current_offset = hashpos <= wpos ? wpos - hashpos : wpos - hashpos + windowsize; + current_offset = (unsigned) (hashpos <= wpos ? wpos - hashpos : wpos - hashpos + windowsize); if(current_offset < prev_offset) break; /*stop when went completely around the circular buffer*/ prev_offset = current_offset; @@ -3446,7 +3446,7 @@ unsigned lodepng_convert(unsigned char* out, const unsigned char* in, for(i = 0; i != palsize; ++i) { const unsigned char* p = &palette[i * 4]; - color_tree_add(&tree, p[0], p[1], p[2], p[3], i); + color_tree_add(&tree, p[0], p[1], p[2], p[3], (unsigned) i); } } @@ -4253,7 +4253,7 @@ static unsigned readChunk_tEXt(LodePNGInfo* info, const unsigned char* data, siz string2_begin = length + 1; /*skip keyword null terminator*/ - length = chunkLength < string2_begin ? 0 : chunkLength - string2_begin; + length = (unsigned) (chunkLength < string2_begin ? 0 : chunkLength - string2_begin); str = (char*)lodepng_malloc(length + 1); if(!str) CERROR_BREAK(error, 83); /*alloc fail*/ @@ -4301,7 +4301,7 @@ static unsigned readChunk_zTXt(LodePNGInfo* info, const LodePNGDecompressSetting string2_begin = length + 2; if(string2_begin > chunkLength) CERROR_BREAK(error, 75); /*no null termination, corrupt?*/ - length = chunkLength - string2_begin; + length = (unsigned) (chunkLength - string2_begin); /*will fail if zlib error, e.g. if length is too small*/ error = zlib_decompress(&decoded.data, &decoded.size, (const unsigned char*)(&data[string2_begin]), @@ -4381,7 +4381,7 @@ static unsigned readChunk_iTXt(LodePNGInfo* info, const LodePNGDecompressSetting /*read the actual text*/ begin += length + 1; - length = chunkLength < begin ? 0 : chunkLength - begin; + length = (unsigned) (chunkLength < begin ? 0 : chunkLength - begin); if(compressed) { @@ -5299,7 +5299,7 @@ static unsigned filter(unsigned char* out, const unsigned char* in, unsigned w, size_t size[5]; unsigned char* attempt[5]; /*five filtering attempts, one for each filter type*/ size_t smallest = 0; - unsigned type = 0, bestType = 0; + unsigned int type = 0, bestType = 0; unsigned char* dummy; LodePNGCompressSettings zlibsettings = settings->zlibsettings; /*use fixed tree on the attempts so that the tree is not adapted to the filtertype on purpose, @@ -5320,7 +5320,7 @@ static unsigned filter(unsigned char* out, const unsigned char* in, unsigned w, { for(type = 0; type != 5; ++type) { - unsigned testsize = linebytes; + unsigned testsize = (unsigned) linebytes; /*if(testsize > 8) testsize /= 8;*/ /*it already works good enough by testing a part of the row*/ filterScanline(attempt[type], &in[y * linebytes], prevline, linebytes, bytewidth, type); @@ -5941,9 +5941,9 @@ unsigned load_file(std::vector& buffer, const std::string& filena if(!file) return 78; /*get filesize*/ - std::streamsize size = 0; - if(file.seekg(0, std::ios::end).good()) size = file.tellg(); - if(file.seekg(0, std::ios::beg).good()) size -= file.tellg(); + std::streamsize size = (std::streamsize) 0; + if(file.seekg(0, std::ios::end).good()) size = (std::streamsize) file.tellg(); + if(file.seekg(0, std::ios::beg).good()) size -= (std::streamsize) file.tellg(); /*read contents of the file into the vector*/ buffer.resize(size_t(size));