This is the mail archive of the ecos-patches@sources.redhat.com mailing list for the eCos project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Fix xyzmodem compressed loads


Index: redboot/current/ChangeLog
===================================================================
RCS file: /cvs/ecos/ecos/packages/redboot/current/ChangeLog,v
retrieving revision 1.79
diff -u -p -5 -r1.79 ChangeLog
--- redboot/current/ChangeLog	12 Sep 2002 21:23:10 -0000	1.79
+++ redboot/current/ChangeLog	13 Sep 2002 21:32:35 -0000
@@ -1,5 +1,10 @@
+2002-09-13  Mark Salter  <msalter@redhat.com>
+
+	* src/decompress.c: Move error handling back into gzip_close to
+	fix xyzmodem loads.
+
 2002-09-12  Mark Salter  <msalter@redhat.com>
 
 	* src/decompress.c (gzip_inflate): Fix error return so that upper
 	doesn't quit on Z_STREAM_END.
 	(gzip_close): Move error handling into gzip_inflate.
Index: redboot/current/src/decompress.c
===================================================================
RCS file: /cvs/ecos/ecos/packages/redboot/current/src/decompress.c,v
retrieving revision 1.6
diff -u -p -5 -r1.6 decompress.c
--- redboot/current/src/decompress.c	12 Sep 2002 21:23:11 -0000	1.6
+++ redboot/current/src/decompress.c	13 Sep 2002 21:32:35 -0000
@@ -55,10 +55,11 @@
 #include <redboot.h>
 
 #ifdef CYGPKG_COMPRESS_ZLIB
 #include <cyg/compress/zlib.h>
 static z_stream stream;
+static bool stream_end;
 
 #define __ZLIB_MAGIC__ 0x5A4C4942   // 'ZLIB'
 
 //
 // Free memory [blocks] are stored as a linked list of "struct _block"
@@ -258,10 +259,11 @@ gzip_init(_pipe_t* p)
     stream.next_in = NULL;
     stream.avail_in = 0;
     stream.next_out = NULL;
     stream.avail_out = 0;
     err = inflateInit(&stream);
+    stream_end = false;
 
     return err;
 }
 
 //
@@ -271,10 +273,13 @@ gzip_init(_pipe_t* p)
 static int
 gzip_inflate(_pipe_t* p)
 {
     int err, bytes_out;
 
+    if (stream_end)
+	return Z_STREAM_END;
+	
     stream.next_in = p->in_buf;
     stream.avail_in = p->in_avail;
     stream.next_out = p->out_buf;
     stream.avail_out = p->out_max;
     err = inflate(&stream, Z_SYNC_FLUSH);
@@ -283,27 +288,17 @@ gzip_inflate(_pipe_t* p)
     p->out_buf = stream.next_out;
     p->msg = stream.msg;
     p->in_avail = stream.avail_in;
     p->in_buf = stream.next_in;
 
-    switch (err) {
-    case Z_STREAM_END:
-	p->in_avail = 0;
-	err = 0;
-	break;
-    case Z_OK:
-	if (bytes_out == 0) {
-	    // Decompression didn't complete
-	    err = -1;
-	    p->msg = "premature end of input";
-	} else
-	    err = 0;
-	break;
-    default:
-	err = -1;
-	break;
+    // Let upper layers process any inflated bytes at
+    // end of stream.
+    if (err == Z_STREAM_END && bytes_out) {
+	stream_end = true;
+	err = Z_OK;
     }
+
     return err;
 }
 
 //
 // Called when the input data is completed or an error has
@@ -311,10 +306,23 @@ gzip_inflate(_pipe_t* p)
 // information up.
 //
 static int
 gzip_close(_pipe_t* p, int err)
 {
+    switch (err) {
+    case Z_STREAM_END:
+        err = 0;
+        break;
+    case Z_OK:
+        // Decompression didn't complete
+        p->msg = "premature end of input";
+        // fall-through
+    default:
+        err = -1;
+        break;
+    }
+
     inflateEnd(&stream);
 
     return err;
 }
 


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]