MCPcopy Create free account
hub / github.com/DFHack/dfhack / zlib_decompress

Function zlib_decompress

depends/lodepng/lodepng.cpp:2226–2249  ·  view source on GitHub ↗

expected_size is expected output size, to avoid intermediate allocations. Set to 0 if not known. */

Source from the content-addressed store, hash-verified

2224
2225/*expected_size is expected output size, to avoid intermediate allocations. Set to 0 if not known. */
2226static unsigned zlib_decompress(unsigned char** out, size_t* outsize, size_t expected_size,
2227 const unsigned char* in, size_t insize, const LodePNGDecompressSettings* settings) {
2228 unsigned error;
2229 if(settings->custom_zlib) {
2230 error = settings->custom_zlib(out, outsize, in, insize, settings);
2231 if(error) {
2232 /*the custom zlib is allowed to have its own error codes, however, we translate it to code 110*/
2233 error = 110;
2234 /*if there's a max output size, and the custom zlib returned error, then indicate that error instead*/
2235 if(settings->max_output_size && *outsize > settings->max_output_size) error = 109;
2236 }
2237 } else {
2238 ucvector v = ucvector_init(*out, *outsize);
2239 if(expected_size) {
2240 /*reserve the memory to avoid intermediate reallocations*/
2241 ucvector_resize(&v, *outsize + expected_size);
2242 v.size = *outsize;
2243 }
2244 error = lodepng_zlib_decompressv(&v, in, insize, settings);
2245 *out = v.data;
2246 *outsize = v.size;
2247 }
2248 return error;
2249}
2250
2251#endif /*LODEPNG_COMPILE_DECODER*/
2252

Callers 5

readChunk_zTXtFunction · 0.85
readChunk_iTXtFunction · 0.85
readChunk_iCCPFunction · 0.85
decodeGenericFunction · 0.85
decompressFunction · 0.85

Calls 3

ucvector_initFunction · 0.85
ucvector_resizeFunction · 0.85
lodepng_zlib_decompressvFunction · 0.85

Tested by

no test coverage detected