Skip to content

Commit

Permalink
Fix overflow
Browse files Browse the repository at this point in the history
  • Loading branch information
spyzhov committed Oct 22, 2024
1 parent 756e129 commit 18b2be3
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 13 deletions.
24 changes: 12 additions & 12 deletions buffer.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,14 +41,14 @@ const (
asterisk byte = '*'
plus byte = '+'
minus byte = '-'
//division byte = '/'
//exclamation byte = '!'
//caret byte = '^'
//signL byte = '<'
//signG byte = '>'
//signE byte = '='
//ampersand byte = '&'
//pipe byte = '|'
// division byte = '/'
// exclamation byte = '!'
// caret byte = '^'
// signL byte = '<'
// signG byte = '>'
// signE byte = '='
// ampersand byte = '&'
// pipe byte = '|'
question byte = '?'
)

Expand Down Expand Up @@ -88,11 +88,11 @@ func (b *buffer) next() (c byte, err error) {
return b.data[b.index], nil
}

func (b *buffer) slice(delta uint) ([]byte, error) {
if b.index+int(delta) > b.length {
func (b *buffer) slice(delta int) ([]byte, error) {
if delta < 0 || b.index+delta > b.length {
return nil, io.EOF
}
return b.data[b.index : b.index+int(delta)], nil
return b.data[b.index : b.index+delta], nil
}

func (b *buffer) move(delta int) error {
Expand Down Expand Up @@ -648,7 +648,7 @@ func (b *buffer) operation() string {
// fixme: add additional order for comparison

for _, operation := range comparisonOperationsOrder() {
if bytes, ok := b.slice(uint(len(operation))); ok == nil {
if bytes, ok := b.slice(len(operation)); ok == nil {
if string(bytes) == operation {
current = operation
_ = b.move(len(operation) - 1) // error can't occupy here because of b.slice result
Expand Down
2 changes: 1 addition & 1 deletion node_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ func TestNode_getValue(t *testing.T) {
keys := []string{"category", "author", "title", "price", "ordered", "tags", "sub"}
for _, key := range keys {
if _, ok := value[key]; !ok {
t.Errorf("Object map has no field: " + key)
t.Errorf("Object map has no field: %s", key)
}
}
}
Expand Down

0 comments on commit 18b2be3

Please sign in to comment.