diff --git a/v2/entropy/ANSRangeCodec.go b/v2/entropy/ANSRangeCodec.go index 65a3caff..2eb9656b 100644 --- a/v2/entropy/ANSRangeCodec.go +++ b/v2/entropy/ANSRangeCodec.go @@ -731,10 +731,10 @@ func (this *ANSRangeDecoder) Read(block []byte) (int, error) { for startChunk < end { endChunk := min(startChunk+sizeChunk, end) sizeChunk = endChunk - startChunk - alphabetSize, err := this.decodeHeader(this.freqs, alphabet[:]) + alphabetSize, errH := this.decodeHeader(this.freqs, alphabet[:]) - if err != nil || alphabetSize == 0 { - return startChunk, err + if errH != nil || alphabetSize == 0 { + return startChunk, errH } if this.order == 0 && alphabetSize == 1 { diff --git a/v2/io/CompressedStream.go b/v2/io/CompressedStream.go index c8ed6958..5d36362d 100644 --- a/v2/io/CompressedStream.go +++ b/v2/io/CompressedStream.go @@ -842,7 +842,7 @@ func (this *encodingTask) encode(res *encodingTaskResult) { func notifyListeners(listeners []kanzi.Listener, evt *kanzi.Event) { defer func() { - //nolint + // nolint:staticcheck if r := recover(); r != nil { //lint:ignore SA9003 // Ignore panics in block listeners diff --git a/v2/transform/TextCodec.go b/v2/transform/TextCodec.go index 5ff55ca6..115fdd41 100644 --- a/v2/transform/TextCodec.go +++ b/v2/transform/TextCodec.go @@ -187,8 +187,7 @@ func computeTextStats(block []byte, freqs0 []int, strict bool) byte { return _TC_MASK_NOT_TEXT } - var freqs [256][256]int - freqs1 := freqs[0:256] + freqs1 := make([][256]int, 256) count := len(block) end4 := count & -4 prv := byte(0) @@ -236,16 +235,16 @@ func computeTextStats(block []byte, freqs0 []int, strict bool) byte { notText = true } else { if strict == true { - notText = (nbTextChars < (count >> 2)) || (freqs0[0] >= count/100) || ((nbASCII / 95) < (count / 100)) + notText = (nbTextChars < (count / 4)) || (freqs0[0] >= count/100) || ((nbASCII / 95) < (count / 100)) } else { - notText = (nbTextChars < (count >> 1)) || (freqs0[32] < count/50) + notText = (nbTextChars < (count / 2)) || (freqs0[32] < count/50) } } res := byte(0) if notText == true { - return res | detectTextType(freqs0, freqs[:], count) + return res | detectTextType(freqs0, freqs1[:], count) } if nbBinChars <= count-count/10 { @@ -255,7 +254,7 @@ func computeTextStats(block []byte, freqs0 []int, strict bool) byte { // Getting this flag wrong results in a very small compression speed degradation. f1 := freqs0['<'] f2 := freqs0['>'] - f3 := freqs['&']['a'] + freqs['&']['g'] + freqs['&']['l'] + freqs['&']['q'] + f3 := freqs1['&']['a'] + freqs1['&']['g'] + freqs1['&']['l'] + freqs1['&']['q'] minFreq := (count - nbBinChars) >> 9 if minFreq < 2 { diff --git a/v2/transform/UTFCodec.go b/v2/transform/UTFCodec.go index 880fed3a..8c559053 100644 --- a/v2/transform/UTFCodec.go +++ b/v2/transform/UTFCodec.go @@ -163,11 +163,9 @@ func (this *UTFCodec) Forward(src, dst []byte) (uint, uint, error) { res := s != 0 // Validation of longer sequences // Third byte in [0x80..0xBF] - res = res && ((s != 3) || ((src[i+2] >= 0x80) && (src[i+2] <= 0xBF))) - // Combine third and fourth bytes - v := (uint16(src[i+2]) << 8) | uint16(src[i+3]) + res = res && ((s != 3) || ((src[i+2] & 0xC0) == 0x80)) // Third and fourth bytes in [0x80..0xBF] - res = res && ((s != 4) || (v&0xC0C0) == 0x8080) + res = res && ((s != 4) || ((((uint16(src[i+2]) << 8) | uint16(src[i+3])) & 0xC0C0) == 0x8080)) if aliasMap[val] == 0 { symb[n].sym = int32(val)