Catch browse back beyond start

This commit is contained in:
lash 2023-04-12 08:42:37 +01:00
parent 4da19b3047
commit 719368301b
Signed by untrusted user who does not match committer: lash
GPG Key ID: 21D2E7BB88C2A746
2 changed files with 20 additions and 2 deletions

View File

@ -6,6 +6,13 @@ import (
"strings" "strings"
) )
type IndexError struct {
}
func(err *IndexError) Error() string {
return fmt.Sprintf("already at first index")
}
// State holds the command stack, error condition of a unique execution session. // State holds the command stack, error condition of a unique execution session.
// //
// It also holds cached values for all results of executed symbols. // It also holds cached values for all results of executed symbols.
@ -208,7 +215,7 @@ func(st *State) Previous() (uint16, error) {
return 0, fmt.Errorf("state root node not yet defined") return 0, fmt.Errorf("state root node not yet defined")
} }
if st.sizeIdx == 0 { if st.sizeIdx == 0 {
return 0, fmt.Errorf("already at first index") return 0, &IndexError{} // ("already at first index")
} }
st.sizeIdx -= 1 st.sizeIdx -= 1
s, idx := st.Where() s, idx := st.Where()

View File

@ -313,7 +313,18 @@ func(vm *Vm) RunInCmp(b []byte, ctx context.Context) ([]byte, error) {
} }
target, _, err = applyTarget([]byte(target), vm.st, vm.ca, ctx) target, _, err = applyTarget([]byte(target), vm.st, vm.ca, ctx)
_, ok := err.(*state.IndexError)
if ok {
_, err = vm.st.ResetFlag(state.FLAG_INMATCH)
if err != nil { if err != nil {
panic(err)
}
_, err = vm.st.SetFlag(state.FLAG_READIN)
if err != nil {
panic(err)
}
return b, nil
} else if err != nil {
return b, err return b, err
} }
vm.Reset() vm.Reset()