Skip to content

Commit

Permalink
expression: Fix wrong way to check for overflow (#27122)
Browse files Browse the repository at this point in the history
  • Loading branch information
UBarney authored Aug 20, 2021
1 parent 086a63f commit 949dafb
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 @@ -921,7 +921,7 @@ func (b *builtinArithmeticPlusIntSig) plusUS(result *chunk.Column, lhi64s, rhi64
}
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) {
if result.IsNull(i) {
continue
}
Expand Down
6 changes: 6 additions & 0 deletions expression/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10260,3 +10260,9 @@ func (s *testIntegrationSuite) TestIssue27236(c *C) {
row = tk.MustQuery(`select extract(hour_second from c1) from t order by c1;`)
row.Check(testkit.Rows("-8385959", "7005959"))
}

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"))
}

0 comments on commit 949dafb

Please sign in to comment.