From 18b2be3214092b687a66c0541ee7bf7b9d9a3a75 Mon Sep 17 00:00:00 2001 From: Stepan Pyzhov Date: Tue, 22 Oct 2024 15:06:55 +0200 Subject: [PATCH] Fix overflow --- buffer.go | 24 ++++++++++++------------ node_test.go | 2 +- 2 files changed, 13 insertions(+), 13 deletions(-) diff --git a/buffer.go b/buffer.go index e332877..9fcad46 100644 --- a/buffer.go +++ b/buffer.go @@ -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 = '?' ) @@ -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 { @@ -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 diff --git a/node_test.go b/node_test.go index 6486b2d..3d1ebc1 100644 --- a/node_test.go +++ b/node_test.go @@ -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) } } }