]> git.dujemihanovic.xyz Git - u-boot.git/commitdiff
gunzip: Update lenp even on error
authorSimon Glass <sjg@chromium.org>
Tue, 2 Dec 2014 20:17:39 +0000 (13:17 -0700)
committerTom Rini <trini@ti.com>
Wed, 14 Jan 2015 16:35:44 +0000 (11:35 -0500)
This allows the caller to easily detect how much of the destination buffer
has been used.

Signed-off-by: Simon Glass <sjg@chromium.org>
lib/gunzip.c

index 35abfb38e176ff64b621fbe9d91b3542ce8150cd..f469fcbeadb5c0ceb77bc2e3b7a78a15797ffe6a 100644 (file)
@@ -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;
 }