Skip to content

Commit

Permalink
Support older Go compilers
Browse files Browse the repository at this point in the history
Remove dependency on newer functions.
  • Loading branch information
scudette committed Dec 2, 2024
1 parent e373986 commit dd09e97
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 16 deletions.
2 changes: 0 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
module github.com/Velocidex/go-vmdk

go 1.23

require (
github.com/alecthomas/kingpin/v2 v2.4.0
github.com/sebdah/goldie v1.0.0
Expand Down
29 changes: 15 additions & 14 deletions parser/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"fmt"
"io"
"regexp"
"slices"
"sort"
"strings"
)

Expand Down Expand Up @@ -47,26 +47,27 @@ func (self *VMDKContext) Close() {
func (self *VMDKContext) getExtentForOffset(offset int64) (
extent Extent, err error) {

n, found := slices.BinarySearchFunc(self.extents,
offset, func(item Extent, offset int64) int {
if offset < item.VirtualOffset() {
return 1
} else if offset == item.VirtualOffset() {
return 0
}
return -1
n := sort.Search(len(self.extents),
func(i int) bool {
extent := self.extents[i]
virtual_offset := extent.VirtualOffset()

return virtual_offset > offset
})
if found {
n++
}

if n < 1 || n > len(self.extents) {
return nil, io.EOF
}

extent = self.extents[n-1]
if extent.VirtualOffset() > offset ||
extent.VirtualOffset()+extent.TotalSize() < offset {
virtual_offset := extent.VirtualOffset()
extent_size := extent.TotalSize()

// extent starts after offset.
if virtual_offset > offset ||

// extent ends before offset
virtual_offset+extent_size < offset {
return nil, io.EOF
}

Expand Down

0 comments on commit dd09e97

Please sign in to comment.