Skip to content

Commit

Permalink
expression: Fix wrong way to check for overflow (#27122) (#27417)
Browse files Browse the repository at this point in the history
  • Loading branch information
ti-srebot authored Sep 6, 2021
1 parent a4504d8 commit daa260f
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
2 changes: 1 addition & 1 deletion expression/builtin_arithmetic_vec.go
Original file line number Diff line number Diff line change
Expand Up @@ -881,7 +881,7 @@ func (b *builtinArithmeticPlusIntSig) plusUS(result *chunk.Column, lhi64s, rhi64
if rh < 0 && uint64(-rh) > uint64(lh) {
return types.ErrOverflow.GenWithStackByArgs("BIGINT UNSIGNED", fmt.Sprintf("(%s + %s)", b.args[0].String(), b.args[1].String()))
}
if rh > 0 && uint64(lh) > math.MaxUint64-uint64(lh) {
if rh > 0 && uint64(lh) > math.MaxUint64-uint64(rh) {
return types.ErrOverflow.GenWithStackByArgs("BIGINT UNSIGNED", fmt.Sprintf("(%s + %s)", b.args[0].String(), b.args[1].String()))
}

Expand Down
6 changes: 6 additions & 0 deletions expression/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9216,6 +9216,12 @@ func (s *testIntegrationSuite) TestRefineArgNullValues(c *C) {
))
}

func (s *testIntegrationSuite) TestIssue26977(c *C) {
tk := testkit.NewTestKit(c, s.store)
result := tk.MustQuery("select a + 1 as f from (select cast(0xfffffffffffffff0 as unsigned) as a union select cast(1 as unsigned)) t having f != 2;")
result.Check(testkit.Rows("18446744073709551601"))
}

func (s *testIntegrationSuite) TestIssue26958(c *C) {
tk := testkit.NewTestKit(c, s.store)
tk.MustExec("use test;")
Expand Down

0 comments on commit daa260f

Please sign in to comment.