Compress::Zlib - fix for win32
authorPaul Marquess <paul.marquess@btinternet.com>
Thu, 13 Oct 2005 23:06:25 +0000 (00:06 +0100)
committerSteve Hay <SteveHay@planit.com>
Fri, 14 Oct 2005 08:00:58 +0000 (08:00 +0000)
From: "Paul Marquess" <Paul.Marquess@ntlworld.com>
Message-ID: <002a01c5d042$5c25fea0$1a1c140a@myopwv.com>

p4raw-id: //depot/perl@25758

ext/Compress/Zlib/Zlib.xs

index cace39b..8bf75f1 100644 (file)
@@ -1053,12 +1053,12 @@ deflate (s, buf, output)
 
         if (s->stream.avail_out == 0) {
            /* out of space in the output buffer so make it bigger */
-            s->bufinc *= 2 ;
             Sv_Grow(output, SvLEN(output) + s->bufinc) ;
             cur_length += increment ;
             s->stream.next_out = (Bytef*) SvPVbyte_nolen(output) + cur_length ;
             increment = s->bufinc ;
             s->stream.avail_out = increment;
+            s->bufinc *= 2 ;
         }
 
         RETVAL = deflate(&(s->stream), Z_NO_FLUSH);
@@ -1147,12 +1147,12 @@ flush(s, output, f=Z_FINISH)
     for (;;) {
         if (s->stream.avail_out == 0) {
            /* consumed all the available output, so extend it */
-            s->bufinc *= 2 ;
             Sv_Grow(output, SvLEN(output) + s->bufinc) ;
             cur_length += increment ;
             s->stream.next_out = (Bytef*) SvPVbyte_nolen(output) + cur_length ;
             increment = s->bufinc ;
             s->stream.avail_out = increment;
+            s->bufinc *= 2 ;
         }
         RETVAL = deflate(&(s->stream), f);
     
@@ -1344,9 +1344,9 @@ inflate (s, buf, output)
     Compress::Zlib::inflateStream      s
     SV *       buf
     SV *       output 
-    uInt       cur_length = NO_INIT
-    uInt       prefix_length = NO_INIT
-    uInt       increment = NO_INIT
+    uInt       cur_length = 0;
+    uInt       prefix_length = 0;
+    uInt       increment = 0;
     STRLEN  stmp   = NO_INIT
   PREINIT:
 #ifdef UTF8_AVAILABLE    
@@ -1378,22 +1378,27 @@ inflate (s, buf, output)
     if((s->flags & FLAG_APPEND) != FLAG_APPEND) {
         SvCUR_set(output, 0);
     }
-    prefix_length = cur_length =  SvCUR(output) ;
-    s->stream.next_out = (Bytef*) SvPVbyte_nolen(output) + cur_length;
-    increment =  SvLEN(output) -  cur_length;
-    s->stream.avail_out =  increment;
+    if (SvLEN(output)) {
+        prefix_length = cur_length =  SvCUR(output) ;
+        s->stream.next_out = (Bytef*) SvPVbyte_nolen(output) + cur_length;
+        increment = SvLEN(output) -  cur_length - 1;
+        s->stream.avail_out = increment;
+    }
+    else {
+        s->stream.avail_out = 0;
+    }
     s->bytesInflated = 0;
     
     while (1) {
 
         if (s->stream.avail_out == 0) {
            /* out of space in the output buffer so make it bigger */
-            s->bufinc *= 2 ;
-            Sv_Grow(output, SvLEN(output) + s->bufinc + 1) ;
+            Sv_Grow(output, SvLEN(output) + s->bufinc) ;
             cur_length += increment ;
             s->stream.next_out = (Bytef*) SvPVbyte_nolen(output) + cur_length ;
             increment = s->bufinc ;
             s->stream.avail_out = increment;
+            s->bufinc *= 2 ;
         }
 
         RETVAL = inflate(&(s->stream), Z_SYNC_FLUSH);