diff options
author | Lode <lvandeve@gmail.com> | 2022-07-18 01:53:17 +0300 |
---|---|---|
committer | Lode <lvandeve@gmail.com> | 2022-07-18 01:53:17 +0300 |
commit | 18964554bc769255401942e0e6dfd09f2fab2093 (patch) | |
tree | 7aa013025d3d147f2702083e53a704195877b47d | |
parent | b4ed2cd7ecf61d29076169b49199371456d4f90b (diff) |
fix a few possible empty vector accesses (C++11 not yet used for now), and cleanup a few other unneeded [0]'s
-rw-r--r-- | lodepng.cpp | 18 | ||||
-rw-r--r-- | lodepng.h | 2 | ||||
-rw-r--r-- | lodepng_util.cpp | 16 |
3 files changed, 18 insertions, 18 deletions
diff --git a/lodepng.cpp b/lodepng.cpp index 33f3ea5..1f89677 100644 --- a/lodepng.cpp +++ b/lodepng.cpp @@ -1,5 +1,5 @@ /* -LodePNG version 20220618 +LodePNG version 20220717 Copyright (c) 2005-2022 Lode Vandevenne @@ -44,7 +44,7 @@ Rename this file to lodepng.cpp to use it for C++, or to lodepng.c to use it for #pragma warning( disable : 4996 ) /*VS does not like fopen, but fopen_s is not standard C so unusable here*/ #endif /*_MSC_VER */ -const char* LODEPNG_VERSION_STRING = "20220618"; +const char* LODEPNG_VERSION_STRING = "20220717"; /* This source file is divided into the following large parts. The code sections @@ -2461,7 +2461,7 @@ static void setBitOfReversedStream(size_t* bitpointer, unsigned char* bitstream, /* ////////////////////////////////////////////////////////////////////////// */ unsigned lodepng_chunk_length(const unsigned char* chunk) { - return lodepng_read32bitInt(&chunk[0]); + return lodepng_read32bitInt(chunk); } void lodepng_chunk_type(char type[5], const unsigned char* chunk) { @@ -6488,7 +6488,7 @@ unsigned decompress(std::vector<unsigned char>& out, const unsigned char* in, si size_t buffersize = 0; unsigned error = zlib_decompress(&buffer, &buffersize, 0, in, insize, &settings); if(buffer) { - out.insert(out.end(), &buffer[0], &buffer[buffersize]); + out.insert(out.end(), buffer, &buffer[buffersize]); lodepng_free(buffer); } return error; @@ -6507,7 +6507,7 @@ unsigned compress(std::vector<unsigned char>& out, const unsigned char* in, size size_t buffersize = 0; unsigned error = zlib_compress(&buffer, &buffersize, in, insize, &settings); if(buffer) { - out.insert(out.end(), &buffer[0], &buffer[buffersize]); + out.insert(out.end(), buffer, &buffer[buffersize]); lodepng_free(buffer); } return error; @@ -6552,7 +6552,7 @@ unsigned decode(std::vector<unsigned char>& out, unsigned& w, unsigned& h, const state.info_raw.colortype = colortype; state.info_raw.bitdepth = bitdepth; size_t buffersize = lodepng_get_raw_size(w, h, &state.info_raw); - out.insert(out.end(), &buffer[0], &buffer[buffersize]); + out.insert(out.end(), buffer, &buffer[buffersize]); } lodepng_free(buffer); return error; @@ -6570,7 +6570,7 @@ unsigned decode(std::vector<unsigned char>& out, unsigned& w, unsigned& h, unsigned error = lodepng_decode(&buffer, &w, &h, &state, in, insize); if(buffer && !error) { size_t buffersize = lodepng_get_raw_size(w, h, &state.info_raw); - out.insert(out.end(), &buffer[0], &buffer[buffersize]); + out.insert(out.end(), buffer, &buffer[buffersize]); } lodepng_free(buffer); return error; @@ -6602,7 +6602,7 @@ unsigned encode(std::vector<unsigned char>& out, const unsigned char* in, unsign size_t buffersize; unsigned error = lodepng_encode_memory(&buffer, &buffersize, in, w, h, colortype, bitdepth); if(buffer) { - out.insert(out.end(), &buffer[0], &buffer[buffersize]); + out.insert(out.end(), buffer, &buffer[buffersize]); lodepng_free(buffer); } return error; @@ -6622,7 +6622,7 @@ unsigned encode(std::vector<unsigned char>& out, size_t buffersize; unsigned error = lodepng_encode(&buffer, &buffersize, in, w, h, &state); if(buffer) { - out.insert(out.end(), &buffer[0], &buffer[buffersize]); + out.insert(out.end(), buffer, &buffer[buffersize]); lodepng_free(buffer); } return error; @@ -1,5 +1,5 @@ /* -LodePNG version 20220618 +LodePNG version 20220717 Copyright (c) 2005-2022 Lode Vandevenne diff --git a/lodepng_util.cpp b/lodepng_util.cpp index 95aaeb1..6d75c23 100644 --- a/lodepng_util.cpp +++ b/lodepng_util.cpp @@ -31,7 +31,7 @@ namespace lodepng { LodePNGInfo getPNGHeaderInfo(const std::vector<unsigned char>& png) { unsigned w, h; lodepng::State state; - lodepng_inspect(&w, &h, &state, &png[0], png.size()); + lodepng_inspect(&w, &h, &state, png.empty() ? NULL : &png[0], png.size()); return state.info_png; } @@ -139,7 +139,7 @@ unsigned getFilterTypesInterlaced(std::vector<std::vector<unsigned char> >& filt lodepng::State state; unsigned w, h; unsigned error; - error = lodepng_inspect(&w, &h, &state, &png[0], png.size()); + error = lodepng_inspect(&w, &h, &state, png.empty() ? NULL : &png[0], png.size()); if(error) return 1; @@ -173,7 +173,7 @@ unsigned getFilterTypesInterlaced(std::vector<std::vector<unsigned char> >& filt //Decompress all IDAT data (if the while loop ended early, this might fail) std::vector<unsigned char> data; - error = lodepng::decompress(data, &zdata[0], zdata.size()); + error = lodepng::decompress(data, zdata.empty() ? NULL : &zdata[0], zdata.size()); if(error) return 1; @@ -230,7 +230,7 @@ unsigned getFilterTypes(std::vector<unsigned char>& filterTypes, const std::vect const unsigned shift1[8] = {1, 1, 1, 1, 1, 1, 1, 1}; lodepng::State state; unsigned w, h; - lodepng_inspect(&w, &h, &state, &png[0], png.size()); + lodepng_inspect(&w, &h, &state, png.empty() ? NULL : &png[0], png.size()); const unsigned* column = w > 1 ? column1 : column0; const unsigned* shift = w > 1 ? shift1 : shift0; for(size_t i = 0; i < h; i++) { @@ -1404,8 +1404,8 @@ unsigned convertRGBModel(unsigned char* out, const unsigned char* in, unsigned error = 0; float* xyz = (float*)lodepng_malloc(w * h * 4 * sizeof(float)); float whitepoint[3]; - error = convertToXYZ(&xyz[0], whitepoint, in, w, h, state_in); - if (!error) error = convertFromXYZ(out, &xyz[0], w, h, state_out, whitepoint, rendering_intent); + error = convertToXYZ(xyz, whitepoint, in, w, h, state_in); + if (!error) error = convertFromXYZ(out, xyz, w, h, state_out, whitepoint, rendering_intent); lodepng_free(xyz); return error; } @@ -1691,7 +1691,7 @@ struct ExtractPNG { //PNG decoding and information extraction void decode(const unsigned char* in, size_t size) { error = 0; if(size == 0 || in == 0) { error = 48; return; } //the given data is empty - readPngHeader(&in[0], size); if(error) return; + readPngHeader(in, size); if(error) return; size_t pos = 33; //first byte of the first chunk after the header std::vector<unsigned char> idat; //the data from idat chunks bool IEND = false; @@ -1754,7 +1754,7 @@ struct ExtractPNG { //PNG decoding and information extraction unsigned extractZlibInfo(std::vector<ZlibBlockInfo>& zlibinfo, const std::vector<unsigned char>& in) { ExtractPNG decoder(&zlibinfo); - decoder.decode(&in[0], in.size()); + decoder.decode(in.empty() ? NULL : &in[0], in.size()); return decoder.error ? 1 : 0; } |