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

fix compatibility bug with convert string to int return wrong result #7483

Merged
merged 8 commits into from
Aug 31, 2018
Prev Previous commit
Next Next commit
types: change AppendError to AppendWarning when convert to int overflows
  • Loading branch information
CodeRushing committed Aug 27, 2018
commit 4995e151463bc71f874c03ef2d54c44b6ed7b340
4 changes: 2 additions & 2 deletions types/convert.go
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,7 @@ func floatStrToIntStr(sc *stmtctx.StatementContext, validFloat string, oriStr st
}
if exp > 0 && int64(intCnt) > (math.MaxInt64-int64(exp)) {
// (exp + incCnt) overflows MaxInt64.
sc.AppendError(ErrOverflow.GenByArgs("BIGINT", oriStr))
sc.AppendWarning(ErrOverflow.GenByArgs("BIGINT", oriStr))
return validFloat[:eIdx], nil
}
intCnt += exp
Expand All @@ -293,7 +293,7 @@ func floatStrToIntStr(sc *stmtctx.StatementContext, validFloat string, oriStr st
extraZeroCount := intCnt - len(digits)
if extraZeroCount > 20 {
// Return overflow to avoid allocating too much memory.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we update this comment?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@CodeRushing Please update this comment.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@zz-jason already updated

sc.AppendError(ErrOverflow.GenByArgs("BIGINT", oriStr))
sc.AppendWarning(ErrOverflow.GenByArgs("BIGINT", oriStr))
return validFloat[:eIdx], nil
}
validInt = string(digits) + strings.Repeat("0", extraZeroCount)
Expand Down