Skip to content

Commit

Permalink
Fix negative slice indexes.
Browse files Browse the repository at this point in the history
  • Loading branch information
andybalholm committed Mar 23, 2019
1 parent 08371dc commit 45f5d9b
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions compress_fragment_two_pass.go
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,7 @@ func createCommands(input []byte, block_size uint, input_size uint, base_ip_ptr

next_hash = hash1(input[next_ip:], shift, min_match)
candidate = ip - last_distance
if isMatch1(input[ip:], input[candidate:], min_match) {
if isMatch1(input[ip:], base_ip_ptr[candidate-base_ip:], min_match) {
if candidate < ip {
table[hash] = int(ip - base_ip)
break
Expand All @@ -290,7 +290,7 @@ func createCommands(input []byte, block_size uint, input_size uint, base_ip_ptr
assert(candidate < ip)

table[hash] = int(ip - base_ip)
if !(!isMatch1(input[ip:], input[candidate:], min_match)) {
if isMatch1(input[ip:], base_ip_ptr[candidate-base_ip:], min_match) {
break
}
}
Expand All @@ -308,7 +308,7 @@ func createCommands(input []byte, block_size uint, input_size uint, base_ip_ptr
{
var base int = ip
/* > 0 */
var matched uint = min_match + findMatchLengthWithLimit(input[uint(candidate)+min_match:], input[uint(ip)+min_match:], uint(ip_end-ip)-min_match)
var matched uint = min_match + findMatchLengthWithLimit(base_ip_ptr[uint(candidate-base_ip)+min_match:], input[uint(ip)+min_match:], uint(ip_end-ip)-min_match)
var distance int = int(base - candidate)
/* We have a 6-byte match at ip, and we need to emit bytes in
[next_emit, ip). */
Expand Down Expand Up @@ -370,12 +370,12 @@ func createCommands(input []byte, block_size uint, input_size uint, base_ip_ptr
}
}

for ip-candidate <= maxDistance_compress_fragment && isMatch1(input[ip:], input[candidate:], min_match) {
for ip-candidate <= maxDistance_compress_fragment && isMatch1(input[ip:], base_ip_ptr[candidate-base_ip:], min_match) {
var base int = ip
/* We have a 6-byte match at ip, and no need to emit any
literal bytes prior to ip. */

var matched uint = min_match + findMatchLengthWithLimit(input[uint(candidate)+min_match:], input[uint(ip)+min_match:], uint(ip_end-ip)-min_match)
var matched uint = min_match + findMatchLengthWithLimit(base_ip_ptr[uint(candidate-base_ip)+min_match:], input[uint(ip)+min_match:], uint(ip_end-ip)-min_match)
ip += int(matched)
last_distance = int(base - candidate) /* > 0 */
emitCopyLen(matched, commands)
Expand Down

0 comments on commit 45f5d9b

Please sign in to comment.