Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

expression: fix painc on substring_index (#7806) #7896

Merged
merged 2 commits into from
Oct 15, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions expression/builtin_string.go
Original file line number Diff line number Diff line change
Expand Up @@ -1209,6 +1209,11 @@ func (b *builtinSubstringIndexSig) evalString(row types.Row) (d string, isNull b
} else {
// If count is negative, everything to the right of the final delimiter (counting from the right) is returned.
count = -count
if count < 0 {
// -count overflows max int64, returns an empty string.
return "", false, nil
}

if count < end {
start = end - count
}
Expand Down
1 change: 1 addition & 0 deletions expression/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -736,6 +736,7 @@ func (s *testIntegrationSuite) TestStringBuiltin(c *C) {
result.Check(testkit.Rows("www.pingcap 12345 45 2017 01:01"))
result = tk.MustQuery(`select substring_index('www.pingcap.com', '.', 0), substring_index('www.pingcap.com', '.', 100), substring_index('www.pingcap.com', '.', -100)`)
result.Check(testkit.Rows(" www.pingcap.com www.pingcap.com"))
tk.MustQuery(`select substring_index('xyz', 'abc', 9223372036854775808)`).Check(testkit.Rows(``))
result = tk.MustQuery(`select substring_index('www.pingcap.com', 'd', 1), substring_index('www.pingcap.com', '', 1), substring_index('', '.', 1)`)
result.Check(testutil.RowsWithSep(",", "www.pingcap.com,,"))
result = tk.MustQuery(`select substring_index(null, '.', 1), substring_index('www.pingcap.com', null, 1), substring_index('www.pingcap.com', '.', null)`)
Expand Down