From: Simon Glass Date: Tue, 2 Dec 2014 13:17:39 -0700 Subject: [U-Boot] [PATCH v2 11/12] gunzip: Update lenp even on error In-Reply-To: <1417551460-10000-1-git-send-email-sjg@chromium.org> References: <1417551460-10000-1-git-send-email-sjg@chromium.org> Message-ID: <1417551460-10000-12-git-send-email-sjg@chromium.org> List-Id: MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit To: u-boot@lists.denx.de This allows the caller to easily detect how much of the destination buffer has been used. Signed-off-by: Simon Glass --- Changes in v2: None lib/gunzip.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/lib/gunzip.c b/lib/gunzip.c index 35abfb3..f469fcbe 100644 --- a/lib/gunzip.c +++ b/lib/gunzip.c @@ -73,6 +73,7 @@ int zunzip(void *dst, int dstlen, unsigned char *src, unsigned long *lenp, int stoponerr, int offset) { z_stream s; + int err = 0; int r; s.zalloc = gzalloc; @@ -92,13 +93,13 @@ int zunzip(void *dst, int dstlen, unsigned char *src, unsigned long *lenp, if (stoponerr == 1 && r != Z_STREAM_END && (s.avail_out == 0 || r != Z_BUF_ERROR)) { printf("Error: inflate() returned %d\n", r); - inflateEnd(&s); - return -1; + err = -1; + break; } s.avail_in = *lenp - offset - (int)(s.next_out - (unsigned char*)dst); } while (r == Z_BUF_ERROR); *lenp = s.next_out - (unsigned char *) dst; inflateEnd(&s); - return 0; + return err; } -- 2.2.0.rc0.207.ga3a616c