Skip to content

Commit

Permalink
[parser] parser: fix signed num will parse error when it encounter tw…
Browse files Browse the repository at this point in the history
…o's complement min (pingcap#905)
  • Loading branch information
AilinKid authored and ti-chi-bot committed Oct 9, 2021
1 parent 14a88e4 commit b5dafb9
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 5 deletions.
15 changes: 12 additions & 3 deletions parser/parser.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 11 additions & 2 deletions parser/parser.y
Original file line number Diff line number Diff line change
Expand Up @@ -11452,9 +11452,18 @@ SignedNum:
{
$$ = $2
}
| '-' Int64Num
| '-' NUM
{
$$ = -$2.(int64)
unsigned_num := getUint64FromNUM($2)
if unsigned_num > 9223372036854775808 {
yylex.AppendError(yylex.Errorf("the Signed Value should be at the range of [-9223372036854775808, 9223372036854775807]."))
return 1
} else if unsigned_num == 9223372036854775808 {
signed_one := int64(1)
$$ = signed_one << 63
} else {
$$ = -int64(unsigned_num)
}
}

DropSequenceStmt:
Expand Down
7 changes: 7 additions & 0 deletions parser/parser_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -861,6 +861,13 @@ AAAAAAAAAAAA5gm5Mg==
// for alter instance.
{"ALTER INSTANCE RELOAD TLS", true, "ALTER INSTANCE RELOAD TLS"},
{"ALTER INSTANCE RELOAD TLS NO ROLLBACK ON ERROR", true, "ALTER INSTANCE RELOAD TLS NO ROLLBACK ON ERROR"},

// for create sequence with signed value especially with Two's Complement Min.
// for issue #17948
{"CREATE SEQUENCE seq INCREMENT - 9223372036854775807", true, "CREATE SEQUENCE `seq` INCREMENT BY -9223372036854775807"},
{"CREATE SEQUENCE seq INCREMENT - 9223372036854775808", true, "CREATE SEQUENCE `seq` INCREMENT BY -9223372036854775808"},
{"CREATE SEQUENCE seq INCREMENT -9223372036854775808", true, "CREATE SEQUENCE `seq` INCREMENT BY -9223372036854775808"},
{"CREATE SEQUENCE seq INCREMENT -9223372036854775809", false, ""},
}
s.RunTest(c, table)
}
Expand Down

0 comments on commit b5dafb9

Please sign in to comment.