From e6af0c35dee641bd494e6fd282e61c6d6b6df46b Mon Sep 17 00:00:00 2001 From: C-3PO Date: Sun, 21 Jul 2019 22:16:00 +0200 Subject: [PATCH] =?UTF-8?q?=F0=9F=8E=A8=20Simplify=20code?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/inflate.c | 27 +++++++++++++-------------- 1 file changed, 13 insertions(+), 14 deletions(-) diff --git a/src/inflate.c b/src/inflate.c index 8f7f1fd..f86cf4d 100644 --- a/src/inflate.c +++ b/src/inflate.c @@ -38,14 +38,14 @@ void inflateInit(uint8_t* comprBufferIn, uint8_t* uncomprBufferIn, unsigned long struct InflateOutput inflateInflate(unsigned long numInputBytes, bool hasMoreBytes) { if (numInputBytes == 0) { - //continue in input buffer where we were before + //Continue in input buffer where we were before } else { - //go back to beginning of input buffer + //Go back to beginning of input buffer comprBufferNext = comprBuffer; remainingInput = numInputBytes; } - //output buffer was previously fully filled and all output was processed. New uncompressed data can be written starting at offset 0 + //Output buffer was previously fully filled and all output was processed. New uncompressed data can be written starting at offset 0 if (spaceInOutput == 0) { uncomprBufferNext = (mz_uint8 *)uncomprBuffer; spaceInOutput = uncomprBufferSize; @@ -77,17 +77,16 @@ struct InflateOutput inflateInflate(unsigned long numInputBytes, bool hasMoreByt spaceInOutput -= out_bytes; out.numBytesWrittenToOutput += out_bytes; - //Check for errors - if (status <= TINFL_STATUS_DONE) { - if (status == TINFL_STATUS_DONE) { - // Decompression completed successfully. - out.hasReachedEnd = true; - break; - } else { - // Decompression failed. - fprintf(stderr, "tinfl_decompress() failed with status %i!\n", status); - errorAndExit(); - } + //Check miniz output + if (status == TINFL_STATUS_DONE) { + // Decompression completed successfully + out.hasReachedEnd = true; + break; + } + if (status < TINFL_STATUS_DONE) { + // Decompression failed + fprintf(stderr, "tinfl_decompress() failed with status %i!\n", status); + errorAndExit(); } if (status == TINFL_STATUS_NEEDS_MORE_INPUT && remainingInput != 0) {