]> git.kernelconcepts.de Git - karo-tx-uboot.git/blobdiff - lib/gunzip.c
FIT: Modify option FIT_SIGNATURE in Kconfig
[karo-tx-uboot.git] / lib / gunzip.c
index 9959781b0004096fe542d950f0cea3f98f066fd3..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;
@@ -89,16 +90,16 @@ int zunzip(void *dst, int dstlen, unsigned char *src, unsigned long *lenp,
        s.avail_out = dstlen;
        do {
                r = inflate(&s, Z_FINISH);
-               if (r != Z_STREAM_END && r != Z_BUF_ERROR && stoponerr == 1) {
+               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);
-               s.avail_out = dstlen;
        } while (r == Z_BUF_ERROR);
        *lenp = s.next_out - (unsigned char *) dst;
        inflateEnd(&s);
 
-       return 0;
+       return err;
 }