Skip to content

Commit

Permalink
Merge pull request #109 from olegshaldybin/fix-off-by-one
Browse files Browse the repository at this point in the history
Fix off-by-one in matchLiteral
  • Loading branch information
derekcollison committed Aug 22, 2015
2 parents 2f83e98 + c226f74 commit b15cde4
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 2 deletions.
3 changes: 1 addition & 2 deletions sublist/sublist.go
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,6 @@ func (s *Sublist) removeFromCache(subject []byte, sub interface{}) {
// slice of results.
func (s *Sublist) Match(subject []byte) []interface{} {
// Fastpath match on cache

s.mu.RLock()
atomic.AddUint64(&s.stats.matches, 1)
r := s.cache.Get(subject)
Expand Down Expand Up @@ -426,7 +425,7 @@ func matchLiteral(literal, subject []byte) bool {
li += 1
}
// Make sure we have processed all of the literal's chars..
if li < (ll - 1) {
if li < ll {
return false
}
return true
Expand Down
2 changes: 2 additions & 0 deletions sublist/sublist_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,8 @@ func TestMatchLiterals(t *testing.T) {
checkBool(matchLiteral([]byte("stats.test.22"), []byte("stats.>")), true, t)
checkBool(matchLiteral([]byte("stats.test.22"), []byte("stats.*.*")), true, t)
checkBool(matchLiteral([]byte("foo.bar"), []byte("foo")), false, t)
checkBool(matchLiteral([]byte("stats.test.foos"), []byte("stats.test.foos")), true, t)
checkBool(matchLiteral([]byte("stats.test.foos"), []byte("stats.test.foo")), false, t)
}

func TestCacheBounds(t *testing.T) {
Expand Down

0 comments on commit b15cde4

Please sign in to comment.