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

Fixed bug on overflown number literals in scanner #569

Merged
merged 3 commits into from
Jul 15, 2019
Merged

Fixed bug on overflown number literals in scanner #569

merged 3 commits into from
Jul 15, 2019

Conversation

dutor
Copy link
Contributor

@dutor dutor commented Jul 2, 2019

As title.

This PR will close #534

@dutor dutor changed the title Fixed bug on overflowed number literals in scanner Fixed bug on overflown number literals in scanner Jul 2, 2019
Copy link
Contributor

@ayyt ayyt left a 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();
}
Copy link
Contributor

@ayyt ayyt Jul 3, 2019

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

Copy link
Contributor Author

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.

Copy link
Contributor

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.

Copy link
Contributor

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]
👍

Copy link
Contributor

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 .

Copy link
Contributor Author

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);
Copy link
Contributor

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?

Copy link
Contributor Author

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.

Copy link
Contributor

Choose a reason for hiding this comment

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

👍

Copy link
Contributor

@ayyt ayyt left a comment

Choose a reason for hiding this comment

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

Well done! I like it.
58338599-a02e2780-7e7a-11e9-8d65-8068da3733c5

@dutor dutor added the ready-for-testing PR: ready for the CI test label Jul 3, 2019
@nebula-community-bot
Copy link
Member

Unit testing passed.

Copy link
Contributor

@laura-ding laura-ding left a comment

Choose a reason for hiding this comment

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

Well done

Copy link
Contributor

@monadbobo monadbobo left a comment

Choose a reason for hiding this comment

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

LGTM.

@nebula-community-bot
Copy link
Member

Unit testing passed.

@dutor dutor merged commit 49dfe49 into vesoft-inc:master Jul 15, 2019
@dutor dutor deleted the fix-overflowed-number-literals branch July 15, 2019 05:16
yixinglu pushed a commit to yixinglu/nebula that referenced this pull request Feb 16, 2020
tong-hao pushed a commit to tong-hao/nebula that referenced this pull request Jun 1, 2021
yixinglu pushed a commit to yixinglu/nebula that referenced this pull request Mar 21, 2022
* 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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ready-for-testing PR: ready for the CI test
Projects
None yet
Development

Successfully merging this pull request may close these issues.

tooooooooooo loooooooongggggggggggggggg id/version number over flow
5 participants