forked from Elara6331/pcre
Fix panic when no substrings are found
This commit is contained in:
parent
bde850752d
commit
d1b9df80a1
15
pcre.go
15
pcre.go
@ -592,12 +592,15 @@ 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:]
|
||||
for i := 0; i < len(ovecSlice); i += 2 {
|
||||
if i+1 >= len(ovecSlice) {
|
||||
cb.Substrings = append(cb.Substrings, cb.Subject[ovecSlice[i]:])
|
||||
} else {
|
||||
cb.Substrings = append(cb.Substrings, cb.Subject[ovecSlice[i]:ovecSlice[i+1]])
|
||||
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]:])
|
||||
} else {
|
||||
cb.Substrings = append(cb.Substrings, cb.Subject[ovecSlice[i]:ovecSlice[i+1]])
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user