diff --git a/src/compress/flate/deflate.go b/src/compress/flate/deflate.go index 550032176d76ca..f64927a7d6ff19 100644 --- a/src/compress/flate/deflate.go +++ b/src/compress/flate/deflate.go @@ -401,9 +401,6 @@ Loop: if !d.sync { break Loop } - if d.index > d.windowEnd { - panic("index > windowEnd") - } if lookahead == 0 { // Flush current output block if any. if d.byteAvailable { @@ -527,10 +524,11 @@ func (d *compressor) fillStore(b []byte) int { } func (d *compressor) store() { - if d.windowEnd > 0 && (d.windowEnd == maxStoreBlockSize || d.sync) { - d.err = d.writeStoredBlock(d.window[:d.windowEnd]) - d.windowEnd = 0 + if !d.sync || d.windowEnd == 0 && d.windowEnd < maxStoreBlockSize { + return } + d.err = d.writeStoredBlock(d.window[:d.windowEnd]) + d.windowEnd = 0 } // storeHuff compresses and stores the currently added data diff --git a/src/compress/flate/huffman_code.go b/src/compress/flate/huffman_code.go index 891537ed5e6343..aa2e3798056849 100644 --- a/src/compress/flate/huffman_code.go +++ b/src/compress/flate/huffman_code.go @@ -287,12 +287,9 @@ func (h *huffmanEncoder) generate(freq []int32, maxBits int32) { list[count] = literalNode{uint16(i), f} count++ } else { - list[count] = literalNode{} h.codes[i].len = 0 } } - list[len(freq)] = literalNode{} - list = list[:count] if count <= 2 { // Handle the small cases here, because they are awkward for the general case code. With