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 for nth_ref_max #1296
Fix for nth_ref_max #1296
Conversation
@@ -7833,7 +7833,7 @@ parse_numvar(struct parser_params *parser) | |||
int overflow; | |||
unsigned long n = ruby_scan_digits(tok()+1, toklen()-1, 10, &len, &overflow); | |||
const unsigned long nth_ref_max = | |||
(FIXNUM_MAX / 2 < INT_MAX) ? FIXNUM_MAX / 2 : INT_MAX; | |||
(FIXNUM_MAX / 2 < INT_MAX) ? FIXNUM_MAX / 2 : INT_MAX / 2; |
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.
Shouldn't the condition be (FIXNUM_MAX / 2 < INT_MAX / 2)
as well?
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 are correct. I simplified the expression to the following, replacing the division with a shift for clarity.
((FIXNUM_MAX < INT_MAX) ? FIXNUM_MAX : INT_MAX) >> 1;
* parse.y (parse_numvar): NTH_REF must be less than a half of INT_MAX, as it is left-shifted to be ORed with back-ref flag. [ruby-core:74444] [Bug#12192] [Fix GH-1296] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_2_1@54275 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* parse.y (parse_numvar): NTH_REF must be less than a half of INT_MAX, as it is left-shifted to be ORed with back-ref flag. [ruby-core:74444] [Bug#12192] [Fix GH-1296] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_2_2@54335 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* parse.y (parse_numvar): NTH_REF must be less than a half of INT_MAX, as it is left-shifted to be ORed with back-ref flag. [ruby-core:74444] [Bug#12192] [Fix GH-1296] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_2_3@54382 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* parse.y (parse_numvar): NTH_REF must be less than a half of INT_MAX, as it is left-shifted to be ORed with back-ref flag. [ruby-core:74444] [Bug#12192] [Fix rubyGH-1296] git-svn-id: svn+ssh://svn.ruby-lang.org/ruby/trunk@54172 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* parse.y (parse_numvar): NTH_REF must be less than a half of INT_MAX, as it is left-shifted to be ORed with back-ref flag. [ruby-core:74444] [Bug#12192] [Fix rubyGH-1296] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@54172 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Fix for the following bug:
https://bugs.ruby-lang.org/issues/12192