Fix panic when no substrings are found

This commit is contained in:
Elara 2023-07-17 07:11:35 -07:00
parent bde850752d
commit d1b9df80a1
1 changed files with 9 additions and 6 deletions

View File

@ -592,7 +592,9 @@ func (r *Regexp) SetCallout(fn func(cb *CalloutBlock) int32) error {
calloutStrBytes := unsafe.Slice((*byte)(unsafe.Pointer(ccb.Fcallout_string)), ccb.Fcallout_string_length)
cb.CalloutString = string(calloutStrBytes)
ovecSlice := unsafe.Slice((*lib.Tsize_t)(unsafe.Pointer(ccb.Foffset_vector)), (ccb.Fcapture_top*2)-1)[2:]
ovecSlice := unsafe.Slice((*lib.Tsize_t)(unsafe.Pointer(ccb.Foffset_vector)), (ccb.Fcapture_top*2)-1)
if len(ovecSlice) > 2 {
ovecSlice = ovecSlice[2:]
for i := 0; i < len(ovecSlice); i += 2 {
if i+1 >= len(ovecSlice) {
cb.Substrings = append(cb.Substrings, cb.Subject[ovecSlice[i]:])
@ -600,6 +602,7 @@ func (r *Regexp) SetCallout(fn func(cb *CalloutBlock) int32) error {
cb.Substrings = append(cb.Substrings, cb.Subject[ovecSlice[i]:ovecSlice[i+1]])
}
}
}
return fn(cb)
}