Fix warnings from go vet.

FIxes #1
This commit is contained in:
Andy Balholm 2019-03-26 06:05:46 -04:00
parent 45f5d9b05a
commit 36f6c9721d
5 changed files with 120 additions and 178 deletions

View File

@ -783,7 +783,6 @@ func readHuffmanCode(alphabet_size uint32, max_symbol uint32, table []huffmanCod
fallthrough fallthrough
/* Read symbols, codes & code lengths directly. */ /* Read symbols, codes & code lengths directly. */
/* Fall through. */
case stateHuffmanSimpleSize: case stateHuffmanSimpleSize:
if !safeReadBits(br, 2, &s.symbol) { /* num_symbols */ if !safeReadBits(br, 2, &s.symbol) { /* num_symbols */
s.substate_huffman = stateHuffmanSimpleSize s.substate_huffman = stateHuffmanSimpleSize
@ -792,7 +791,7 @@ func readHuffmanCode(alphabet_size uint32, max_symbol uint32, table []huffmanCod
s.sub_loop_counter = 0 s.sub_loop_counter = 0
fallthrough fallthrough
/* Fall through. */
case stateHuffmanSimpleRead: case stateHuffmanSimpleRead:
{ {
var result int = readSimpleHuffmanSymbols(alphabet_size, max_symbol, s) var result int = readSimpleHuffmanSymbols(alphabet_size, max_symbol, s)
@ -802,9 +801,7 @@ func readHuffmanCode(alphabet_size uint32, max_symbol uint32, table []huffmanCod
} }
fallthrough fallthrough
/* Fall through. */
case stateHuffmanSimpleBuild: case stateHuffmanSimpleBuild:
{
var table_size uint32 var table_size uint32
if s.symbol == 3 { if s.symbol == 3 {
var bits uint32 var bits uint32
@ -823,8 +820,6 @@ func readHuffmanCode(alphabet_size uint32, max_symbol uint32, table []huffmanCod
s.substate_huffman = stateHuffmanNone s.substate_huffman = stateHuffmanNone
return decoderSuccess return decoderSuccess
}
fallthrough
/* Decode Huffman-coded code lengths. */ /* Decode Huffman-coded code lengths. */
case stateHuffmanComplex: case stateHuffmanComplex:
@ -854,9 +849,7 @@ func readHuffmanCode(alphabet_size uint32, max_symbol uint32, table []huffmanCod
} }
fallthrough fallthrough
/* Fall through. */
case stateHuffmanLengthSymbols: case stateHuffmanLengthSymbols:
{
var table_size uint32 var table_size uint32
var result int = readSymbolCodeLengths(max_symbol, s) var result int = readSymbolCodeLengths(max_symbol, s)
if result == decoderNeedsMoreInput { if result == decoderNeedsMoreInput {
@ -878,8 +871,6 @@ func readHuffmanCode(alphabet_size uint32, max_symbol uint32, table []huffmanCod
s.substate_huffman = stateHuffmanNone s.substate_huffman = stateHuffmanNone
return decoderSuccess return decoderSuccess
}
fallthrough
default: default:
return decoderErrorUnreachable return decoderErrorUnreachable
@ -1111,9 +1102,7 @@ func decodeContextMap(context_map_size uint32, num_htrees *uint32, context_map_a
} }
fallthrough fallthrough
/* Fall through. */
case stateContextMapTransform: case stateContextMapTransform:
{
var bits uint32 var bits uint32
if !safeReadBits(br, 1, &bits) { if !safeReadBits(br, 1, &bits) {
s.substate_context_map = stateContextMapTransform s.substate_context_map = stateContextMapTransform
@ -1126,8 +1115,6 @@ func decodeContextMap(context_map_size uint32, num_htrees *uint32, context_map_a
s.substate_context_map = stateContextMapNone s.substate_context_map = stateContextMapNone
return decoderSuccess return decoderSuccess
}
fallthrough
default: default:
return decoderErrorUnreachable return decoderErrorUnreachable
@ -1423,7 +1410,6 @@ func copyUncompressedBlockToOutput(available_out *uint, next_out *[]byte, total_
} }
fallthrough fallthrough
/* Fall through. */
case stateUncompressedWrite: case stateUncompressedWrite:
{ {
var result int var result int
@ -1441,9 +1427,6 @@ func copyUncompressedBlockToOutput(available_out *uint, next_out *[]byte, total_
} }
} }
} }
assert(false) /* Unreachable */
return 0
} }
/* Calculates the smallest feasible ring buffer. /* Calculates the smallest feasible ring buffer.
@ -1484,8 +1467,6 @@ func calculateRingBufferSize(s *Reader) {
output_size += s.meta_block_remaining_len output_size += s.meta_block_remaining_len
if min_size < output_size { if min_size < output_size {
min_size = output_size min_size = output_size
} else {
min_size = min_size
} }
if !(s.canny_ringbuffer_allocation == 0) { if !(s.canny_ringbuffer_allocation == 0) {
@ -2296,17 +2277,12 @@ func decoderDecompressStream(s *Reader, available_in *uint, next_in *[]byte, ava
s.loop_counter = 0 s.loop_counter = 0
s.state = stateHuffmanCode0 s.state = stateHuffmanCode0
case stateUncompressed:
{
result = copyUncompressedBlockToOutput(available_out, next_out, nil, s)
if result != decoderSuccess {
break
}
case stateUncompressed:
result = copyUncompressedBlockToOutput(available_out, next_out, nil, s)
if result == decoderSuccess {
s.state = stateMetablockDone s.state = stateMetablockDone
break
} }
fallthrough
case stateMetadata: case stateMetadata:
for ; s.meta_block_remaining_len > 0; s.meta_block_remaining_len-- { for ; s.meta_block_remaining_len > 0; s.meta_block_remaining_len-- {
@ -2344,7 +2320,7 @@ func decoderDecompressStream(s *Reader, available_in *uint, next_in *[]byte, ava
s.state = stateHuffmanCode1 s.state = stateHuffmanCode1
fallthrough fallthrough
/* Fall through. */
case stateHuffmanCode1: case stateHuffmanCode1:
{ {
var alphabet_size uint32 = s.num_block_types[s.loop_counter] + 2 var alphabet_size uint32 = s.num_block_types[s.loop_counter] + 2
@ -2357,7 +2333,6 @@ func decoderDecompressStream(s *Reader, available_in *uint, next_in *[]byte, ava
} }
fallthrough fallthrough
/* Fall through. */
case stateHuffmanCode2: case stateHuffmanCode2:
{ {
var alphabet_size uint32 = numBlockLenSymbols var alphabet_size uint32 = numBlockLenSymbols
@ -2370,9 +2345,7 @@ func decoderDecompressStream(s *Reader, available_in *uint, next_in *[]byte, ava
} }
fallthrough fallthrough
/* Fall through. */
case stateHuffmanCode3: case stateHuffmanCode3:
{
var tree_offset int = s.loop_counter * huffmanMaxSize26 var tree_offset int = s.loop_counter * huffmanMaxSize26
if !safeReadBlockLength(s, &s.block_length[s.loop_counter], s.block_len_trees[tree_offset:], br) { if !safeReadBlockLength(s, &s.block_length[s.loop_counter], s.block_len_trees[tree_offset:], br) {
result = decoderNeedsMoreInput result = decoderNeedsMoreInput
@ -2381,9 +2354,7 @@ func decoderDecompressStream(s *Reader, available_in *uint, next_in *[]byte, ava
s.loop_counter++ s.loop_counter++
s.state = stateHuffmanCode0 s.state = stateHuffmanCode0
break
}
fallthrough
case stateMetablockHeader2: case stateMetablockHeader2:
{ {
var bits uint32 var bits uint32
@ -2407,7 +2378,6 @@ func decoderDecompressStream(s *Reader, available_in *uint, next_in *[]byte, ava
} }
fallthrough fallthrough
/* Fall through. */
case stateContextModes: case stateContextModes:
result = readContextModes(s) result = readContextModes(s)
@ -2418,7 +2388,6 @@ func decoderDecompressStream(s *Reader, available_in *uint, next_in *[]byte, ava
s.state = stateContextMap1 s.state = stateContextMap1
fallthrough fallthrough
/* Fall through. */
case stateContextMap1: case stateContextMap1:
result = decodeContextMap(s.num_block_types[0]<<literalContextBits, &s.num_literal_htrees, &s.context_map, s) result = decodeContextMap(s.num_block_types[0]<<literalContextBits, &s.num_literal_htrees, &s.context_map, s)
@ -2429,7 +2398,7 @@ func decoderDecompressStream(s *Reader, available_in *uint, next_in *[]byte, ava
detectTrivialLiteralBlockTypes(s) detectTrivialLiteralBlockTypes(s)
s.state = stateContextMap2 s.state = stateContextMap2
fallthrough fallthrough
/* Fall through. */
case stateContextMap2: case stateContextMap2:
{ {
var num_direct_codes uint32 = s.num_direct_distance_codes - numDistanceShortCodes var num_direct_codes uint32 = s.num_direct_distance_codes - numDistanceShortCodes
@ -2469,9 +2438,7 @@ func decoderDecompressStream(s *Reader, available_in *uint, next_in *[]byte, ava
} }
fallthrough fallthrough
/* Fall through. */
case stateTreeGroup: case stateTreeGroup:
{
var hgroup *huffmanTreeGroup = nil var hgroup *huffmanTreeGroup = nil
switch s.loop_counter { switch s.loop_counter {
case 0: case 0:
@ -2501,31 +2468,14 @@ func decoderDecompressStream(s *Reader, available_in *uint, next_in *[]byte, ava
s.state = stateCommandBegin s.state = stateCommandBegin
} }
break case stateCommandBegin, stateCommandInner, stateCommandPostDecodeLiterals, stateCommandPostWrapCopy:
}
fallthrough
case stateCommandBegin,
/* Fall through. */
stateCommandInner,
/* Fall through. */
stateCommandPostDecodeLiterals,
/* Fall through. */
stateCommandPostWrapCopy:
result = processCommands(s) result = processCommands(s)
if result == decoderNeedsMoreInput { if result == decoderNeedsMoreInput {
result = safeProcessCommands(s) result = safeProcessCommands(s)
} }
case stateCommandInnerWrite, case stateCommandInnerWrite, stateCommandPostWrite1, stateCommandPostWrite2:
/* Fall through. */
stateCommandPostWrite1,
/* Fall through. */
stateCommandPostWrite2:
result = writeRingBuffer(s, available_out, next_out, nil, false) result = writeRingBuffer(s, available_out, next_out, nil, false)
if result != decoderSuccess { if result != decoderSuccess {
@ -2588,7 +2538,6 @@ func decoderDecompressStream(s *Reader, available_in *uint, next_in *[]byte, ava
s.state = stateDone s.state = stateDone
fallthrough fallthrough
/* Fall through. */
case stateDone: case stateDone:
if s.ringbuffer != nil { if s.ringbuffer != nil {
result = writeRingBuffer(s, available_out, next_out, nil, true) result = writeRingBuffer(s, available_out, next_out, nil, true)

View File

@ -957,7 +957,7 @@ func writeMetaBlockInternal(data []byte, mask uint, last_flush_pos uint64, bytes
} }
assert(*storage_ix <= 14) assert(*storage_ix <= 14)
last_bytes = uint16(storage[1]<<8 | storage[0]) last_bytes = uint16(storage[1])<<8 | uint16(storage[0])
last_bytes_bits = byte(*storage_ix) last_bytes_bits = byte(*storage_ix)
if params.quality <= maxQualityForStaticEntropyCodes { if params.quality <= maxQualityForStaticEntropyCodes {
storeMetaBlockFast(data, uint(wrapped_last_flush_pos), bytes, mask, is_last, params, commands, num_commands, storage_ix, storage) storeMetaBlockFast(data, uint(wrapped_last_flush_pos), bytes, mask, is_last, params, commands, num_commands, storage_ix, storage)

View File

@ -606,8 +606,8 @@ func buildSimpleHuffmanTable(table []huffmanCode, root_bits int, val []uint16, n
} }
table_size = 4 table_size = 4
case 3: case 3:
{
var i int var i int
var k int var k int
for i = 0; i < 3; i++ { for i = 0; i < 3; i++ {
@ -625,11 +625,8 @@ func buildSimpleHuffmanTable(table []huffmanCode, root_bits int, val []uint16, n
table[1] = constructHuffmanCode(2, val[2]) table[1] = constructHuffmanCode(2, val[2])
table[3] = constructHuffmanCode(2, val[3]) table[3] = constructHuffmanCode(2, val[3])
table_size = 4 table_size = 4
break
}
fallthrough
case 4: case 4:
{
if val[3] < val[2] { if val[3] < val[2] {
var t uint16 = val[3] var t uint16 = val[3]
val[3] = val[2] val[3] = val[2]
@ -645,8 +642,6 @@ func buildSimpleHuffmanTable(table []huffmanCode, root_bits int, val []uint16, n
table[6] = constructHuffmanCode(1, val[0]) table[6] = constructHuffmanCode(1, val[0])
table[7] = constructHuffmanCode(3, val[3]) table[7] = constructHuffmanCode(3, val[3])
table_size = 8 table_size = 8
break
}
} }
for table_size != goal_size { for table_size != goal_size {

View File

@ -89,6 +89,4 @@ func (r *Reader) Read(p []byte) (n int, err error) {
} }
r.in = r.buf[:encN] r.in = r.buf[:encN]
} }
return n, nil
} }

View File

@ -543,7 +543,7 @@ func shiftTransform(word []byte, word_len int, parameter uint16) int {
if word_len < 3 { if word_len < 3 {
return word_len return word_len
} }
scalar += uint32(word[2]&0x3F | (word[1]&0x3F)<<6 | (word[0]&0x0F)<<12) scalar += uint32(word[2])&0x3F | uint32(word[1]&0x3F)<<6 | uint32(word[0]&0x0F)<<12
word[0] = byte(0xE0 | (scalar>>12)&0x0F) word[0] = byte(0xE0 | (scalar>>12)&0x0F)
word[1] = byte(uint32(word[1]&0xC0) | (scalar>>6)&0x3F) word[1] = byte(uint32(word[1]&0xC0) | (scalar>>6)&0x3F)
word[2] = byte(uint32(word[2]&0xC0) | scalar&0x3F) word[2] = byte(uint32(word[2]&0xC0) | scalar&0x3F)
@ -553,7 +553,7 @@ func shiftTransform(word []byte, word_len int, parameter uint16) int {
if word_len < 4 { if word_len < 4 {
return word_len return word_len
} }
scalar += uint32(word[3]&0x3F | (word[2]&0x3F)<<6 | (word[1]&0x3F)<<12 | (word[0]&0x07)<<18) scalar += uint32(word[3])&0x3F | uint32(word[2]&0x3F)<<6 | uint32(word[1]&0x3F)<<12 | uint32(word[0]&0x07)<<18
word[0] = byte(0xF0 | (scalar>>18)&0x07) word[0] = byte(0xF0 | (scalar>>18)&0x07)
word[1] = byte(uint32(word[1]&0xC0) | (scalar>>12)&0x3F) word[1] = byte(uint32(word[1]&0xC0) | (scalar>>12)&0x3F)
word[2] = byte(uint32(word[2]&0xC0) | (scalar>>6)&0x3F) word[2] = byte(uint32(word[2]&0xC0) | (scalar>>6)&0x3F)
@ -610,10 +610,10 @@ func transformDictionaryWord(dst []byte, word []byte, len int, trans *transforms
len -= step len -= step
} }
} else if t == transformShiftFirst { } else if t == transformShiftFirst {
var param uint16 = uint16(trans.params[transform_idx*2] + (trans.params[transform_idx*2+1] << 8)) var param uint16 = uint16(trans.params[transform_idx*2]) + uint16(trans.params[transform_idx*2+1])<<8
shiftTransform(dst[idx-len:], int(len), param) shiftTransform(dst[idx-len:], int(len), param)
} else if t == transformShiftAll { } else if t == transformShiftAll {
var param uint16 = uint16(trans.params[transform_idx*2] + (trans.params[transform_idx*2+1] << 8)) var param uint16 = uint16(trans.params[transform_idx*2]) + uint16(trans.params[transform_idx*2+1])<<8
var shift []byte = dst var shift []byte = dst
shift = shift[idx-len:] shift = shift[idx-len:]
for len > 0 { for len > 0 {