Skip to contentSkip to conversation

Fix gunzip to work for any gziped uImage size

PATCH New Catalin Radu 2 participants 3 messages Feb 3, 2011 – Feb 4, 2011 Library code

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Fix gunzip to work for any gziped uImage size

---
 lib/gunzip.c |   16 ++++++++++------
 1 files changed, 10 insertions(+), 6 deletions(-)
lib/gunzip.c +10 -6
index 482a476..2922608 100644
@@ -106,12 +106,16 @@ int zunzip(void *dst, int dstlen, unsigned char *src, unsigned long *lenp,
 	s.avail_in = *lenp - offset;
 	s.next_out = dst;
 	s.avail_out = dstlen;
-	r = inflate(&s, Z_FINISH);
-	if ((r != Z_STREAM_END) && (stoponerr==1)) {
-		printf ("Error: inflate() returned %d\n", r);
-		inflateEnd(&s);
-		return (-1);
-	}
+	do {
+		r = inflate(&s, Z_FINISH);
+		if ((r != Z_STREAM_END)&&  (r != Z_BUF_ERROR)&&  (stoponerr==1)) {
+			printf ("Error: inflate() returned %d\n", r);
+			inflateEnd(&s);
+	   		return (-1);
+	   	}
+		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);
 
Signature · 1 line
1.6.3.3
#1 lore raw

PATCH 1/1 Fix gunzip to work for any gziped uImage size

Catalin, greetings!

Some very minor code style issues that I noticed. All cosmetic.

Quoted 11 lines · Catalin Radu
---
 lib/gunzip.c |   16 ++++++++++------
 1 files changed, 10 insertions(+), 6 deletions(-)
lib/gunzip.c +0 -0
index 482a476..2922608 100644
@@ -106,12 +106,16 @@ int zunzip(void *dst, int dstlen, unsigned char *src, unsigned long *lenp,
 	s.avail_in = *lenp - offset;

lib/gunzip.c int zunzip(void *dst, int dstlen, unsigned char *src, unsigned long *lenp, · line 110

Quoted 10 lines
lib/gunzip.c +2 -6
 	s.next_out = dst;
 	s.avail_out = dstlen;
-	r = inflate(&s, Z_FINISH);
-	if ((r != Z_STREAM_END) && (stoponerr==1)) {
-		printf ("Error: inflate() returned %d\n", r);
-		inflateEnd(&s);
-		return (-1);
-	}
+	do {
+		r = inflate(&s, Z_FINISH);

Space after function name?

lib/gunzip.c int zunzip(void *dst, int dstlen, unsigned char *src, unsigned long *lenp, · line 111

Quoted 1 line
lib/gunzip.c +1 -0
+		if ((r != Z_STREAM_END)&&  (r != Z_BUF_ERROR)&&  (stoponerr==1)) {

Inconsistent spacing around && operator.

Parentheses around each condition are unnecessary (both "==" and "!=" bind tighter than "&&"), but I suppose that's basically personal preference (and the code being replaced did it that way.)

lib/gunzip.c int zunzip(void *dst, int dstlen, unsigned char *src, unsigned long *lenp, · line 113

Quoted 2 lines
lib/gunzip.c +2 -0
+			printf ("Error: inflate() returned %d\n", r);
+			inflateEnd(&s);

Space after function name?

lib/gunzip.c int zunzip(void *dst, int dstlen, unsigned char *src, unsigned long *lenp, · line 114

Quoted 1 line
lib/gunzip.c +1 -0
+	   		return (-1);

These parentheses are unnecessary. (Another question of taste:
"return" is a keyword, not a function.)

lib/gunzip.c int zunzip(void *dst, int dstlen, unsigned char *src, unsigned long *lenp, · line 120

Quoted 6 lines
lib/gunzip.c +4 -0
+	   	}
+		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);

Space after function name?

As I said, all totally trivial, but especially those "&& " caught my eye. :)

Best regards,
Tony

#2 lore raw

PATCH 1/1 Fix gunzip to work for any gziped uImage size

Quoted 67 lines · Anthony Foiani

Catalin, greetings!

Some very minor code style issues that I noticed. All cosmetic.

Quoted 12 lines · Catalin Radu
---
 lib/gunzip.c |   16 ++++++++++------
 1 files changed, 10 insertions(+), 6 deletions(-)
lib/gunzip.c +0 -0
index 482a476..2922608 100644
@@ -106,12 +106,16 @@ int zunzip(void *dst, int dstlen, unsigned char *src, unsigned long *lenp,
 	s.avail_in = *lenp - offset;
 	s.next_out = dst;

lib/gunzip.c int zunzip(void *dst, int dstlen, unsigned char *src, unsigned long *lenp, · line 111

Quoted 10 lines
lib/gunzip.c +2 -6
 	s.avail_out = dstlen;
-	r = inflate(&s, Z_FINISH);
-	if ((r != Z_STREAM_END) && (stoponerr==1)) {
-		printf ("Error: inflate() returned %d\n", r);
-		inflateEnd(&s);
-		return (-1);
-	}
+	do {
+		r = inflate(&s, Z_FINISH);
 

Space after function name?

lib/gunzip.c int zunzip(void *dst, int dstlen, unsigned char *src, unsigned long *lenp, · line 121

Quoted 2 lines
lib/gunzip.c +1 -0
+		if ((r != Z_STREAM_END)&&  (r != Z_BUF_ERROR)&&  (stoponerr==1)) {
 

Inconsistent spacing around && operator.

Parentheses around each condition are unnecessary (both "==" and "!=" bind tighter than "&&"), but I suppose that's basically personal preference (and the code being replaced did it that way.)

lib/gunzip.c int zunzip(void *dst, int dstlen, unsigned char *src, unsigned long *lenp, · line 121

Quoted 3 lines
lib/gunzip.c +2 -0
+			printf ("Error: inflate() returned %d\n", r);
+			inflateEnd(&s);
 

Space after function name?

lib/gunzip.c int zunzip(void *dst, int dstlen, unsigned char *src, unsigned long *lenp, · line 114

Quoted 2 lines
lib/gunzip.c +1 -0
+	   		return (-1);

These parentheses are unnecessary. (Another question of taste:
"return" is a keyword, not a function.)

lib/gunzip.c int zunzip(void *dst, int dstlen, unsigned char *src, unsigned long *lenp, · line 120

Quoted 7 lines
lib/gunzip.c +4 -0
+	   	}
+		s.avail_in = *lenp - offset - (int)(s.next_out - (unsigned char*)dst);
+		s.avail_out = dstlen;
+	} while (r == Z_BUF_ERROR);
lib/gunzip.c +0 -0
 	*lenp = s.next_out - (unsigned char *) dst;
 	inflateEnd(&s);

Space after function name?

Quoted 5 lines

As I said, all totally trivial, but especially those "&& " caught my eye. :)

Best regards,
Tony

Greetings Tony,

Thanks for the formatting observations. I will resend the re-formatted patch.

Regards,
Catalin