-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
Fixed bug on overflown number literals in scanner #569
Fixed bug on overflown number literals in scanner #569
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well done! 👍 , I added some inline comments.
} | ||
if (yyleng - i > 16) { | ||
yyterminate(); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The maximum value of int64 is 9,223,372,036,854,775,807,
Hexadecimal is 0X7FFF FFFF FFFF FFFF
when value is in [ 0X8000 0000 0000 0000, 0XFFFF FFFF FFFF FFFF] , the value is still overflow.
So, here add esle statement
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hex is a way to specify integers as raw bytes, there is no such thing overflow in terms of literals.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if (yyleng - i == 16 && yytext[i] > 7 ), Does the hexadecimal value not overflow?
the value in decimal is great than 9,223,372,036,854,775,807.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, you are right, [-9,223,372,036,854,775,808 9,223,372,036,854,775,807] is [0, 0XFFFF FFFF FFFF FFFF]
👍
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you can replace magic number "18" with std::numeric_limits<int64_t>::digits10 .
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@monadbobo But here we are dealing with hexdecimal, instead of base 10.
if (yyleng - i > 16) { | ||
yyterminate(); | ||
} | ||
} | ||
int64_t val = 0; | ||
sscanf(yytext, "%lx", &val); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we judge the return value of sscanf?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, we should have done that, even though the regex and checking above already guarantee the correctness.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unit testing passed. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well done
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM.
Unit testing passed. |
* parse date * enhance datetime * add test * fix review * rename Co-authored-by: Sophie <84560950+Sophie-Xie@users.noreply.github.com> Co-authored-by: jakevin <30525741+jackwener@users.noreply.github.com> Co-authored-by: Sophie <84560950+Sophie-Xie@users.noreply.github.com>
As title.
This PR will close #534