Skip to content

Commit

Permalink
Fix deflateEnd() to not report an error at start of raw deflate.
Browse files Browse the repository at this point in the history
  • Loading branch information
madler committed Oct 13, 2017
1 parent 288f108 commit c376a41
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion deflate.c
Original file line number Diff line number Diff line change
Expand Up @@ -491,7 +491,7 @@ int ZEXPORT deflateResetKeep (strm)
#ifdef GZIP
s->wrap == 2 ? GZIP_STATE :
#endif
s->wrap ? INIT_STATE : BUSY_STATE;
INIT_STATE;
strm->adler =
#ifdef GZIP
s->wrap == 2 ? crc32(0L, Z_NULL, 0) :
Expand Down Expand Up @@ -814,6 +814,8 @@ int ZEXPORT deflate (strm, flush)
}

/* Write the header */
if (s->status == INIT_STATE && s->wrap == 0)

This comment has been minimized.

Copy link
@irwir

irwir Oct 13, 2017

One comparison can be removed:

if (s->status == INIT_STATE)
    if (s->wrap == 0)
        s->status = BUSY_STATE;
    else {
    . . .
    }

This comment has been minimized.

Copy link
@madler

madler Oct 13, 2017

Author Owner

The compiler can find that optimization. I wanted to minimize the change for easier inspection of no harm done.

This comment has been minimized.

Copy link
@irwir

irwir Oct 13, 2017

The latest VS 2017, optimizations on.
Original:

cmp  eax,2Ah
jne  deflate+12Dh
cmp  dword ptr [rbx+2Ch],esi
jne  deflate+12Dh
mov  dword ptr [rbx+8],71h
cmp  dword ptr [rbx+8],2Ah
jne  deflate+1E7h

After the suggested change:

cmp  eax,2Ah
jne  deflate+1EAh
cmp  dword ptr [rbx+2Ch],esi
jne  deflate+13Ah
mov  dword ptr [rbx+8],71h
jmp  deflate+1EAh

s->status = BUSY_STATE;
if (s->status == INIT_STATE) {
/* zlib header */
uInt header = (Z_DEFLATED + ((s->w_bits-8)<<4)) << 8;
Expand Down

1 comment on commit c376a41

@AnHeBridgeNorth
Copy link

@AnHeBridgeNorth AnHeBridgeNorth commented on c376a41 Apr 14, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is the impact of this patch?

Please sign in to comment.