mirror of
https://github.com/soheilhy/cmux.git
synced 2024-11-14 11:31:28 +08:00
Merge pull request #33 from soheilhy/fix-b32
Fix index out of range in patricia tree
This commit is contained in:
commit
b26951527b
@ -161,6 +161,10 @@ func (n *ptNode) match(b []byte, prefix bool) bool {
|
|||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if l >= len(b) {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
nextN, ok := n.next[b[l]]
|
nextN, ok := n.next[b[l]]
|
||||||
if !ok {
|
if !ok {
|
||||||
return false
|
return false
|
||||||
|
@ -33,6 +33,13 @@ func testPTree(t *testing.T, strs ...string) {
|
|||||||
if pt.match(strings.NewReader(s + s)) {
|
if pt.match(strings.NewReader(s + s)) {
|
||||||
t.Errorf("%s matches %s", s+s, s)
|
t.Errorf("%s matches %s", s+s, s)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// The following tests are just to catch index out of
|
||||||
|
// range and off-by-one errors and not the functionality.
|
||||||
|
pt.matchPrefix(strings.NewReader(s[:len(s)-1]))
|
||||||
|
pt.match(strings.NewReader(s[:len(s)-1]))
|
||||||
|
pt.matchPrefix(strings.NewReader(s + "$"))
|
||||||
|
pt.match(strings.NewReader(s + "$"))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -45,5 +52,5 @@ func TestPatriciaNonOverlapping(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestPatriciaOverlapping(t *testing.T) {
|
func TestPatriciaOverlapping(t *testing.T) {
|
||||||
testPTree(t, "foo", "far", "farther", "boo", "bar")
|
testPTree(t, "foo", "far", "farther", "boo", "ba", "bar")
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user