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 for nth_ref_max #1296

Closed
wants to merge 1 commit into from
Closed

Fix for nth_ref_max #1296

wants to merge 1 commit into from

Conversation

ghost
Copy link

@ghost ghost commented Mar 17, 2016

Fix for the following bug:

https://bugs.ruby-lang.org/issues/12192

@@ -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;
Copy link
Member

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?

Copy link
Author

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;

@hsbt hsbt closed this in 7a3cc69 Mar 18, 2016
hsbt pushed a commit that referenced this pull request Mar 25, 2016
	* 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
hsbt pushed a commit that referenced this pull request Mar 28, 2016
	* 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
hsbt pushed a commit that referenced this pull request Mar 29, 2016
	* 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
mrkn pushed a commit to mrkn/ruby that referenced this pull request Apr 17, 2016
* 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
tenderlove pushed a commit to tenderlove/ruby that referenced this pull request May 1, 2016
* 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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
1 participant