ruby-changes:49782
From: nobu <ko1@a...>
Date: Thu, 18 Jan 2018 12:29:18 +0900 (JST)
Subject: [ruby-changes:49782] nobu:r61900 (trunk): parse.y: fix overflow
nobu 2018-01-18 12:29:12 +0900 (Thu, 18 Jan 2018) New Revision: 61900 https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=61900 Log: parse.y: fix overflow Modified files: trunk/parse.y trunk/test/-ext-/ast/test_ast.rb Index: test/-ext-/ast/test_ast.rb =================================================================== --- test/-ext-/ast/test_ast.rb (revision 61899) +++ test/-ext-/ast/test_ast.rb (revision 61900) @@ -129,4 +129,12 @@ class TestAst < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/-ext-/ast/test_ast.rb#L129 assert_equal([], helper.errors) end end + + def test_column_with_long_heredoc_identifier + term = "A"*257 + ast = AST.parse("<<-#{term}\n""ddddddd\n#{term}\n") + node = ast.children[1] + assert_equal("NODE_STR", node.type) + assert_equal(0, node.first_column) + end end Index: parse.y =================================================================== --- parse.y (revision 61899) +++ parse.y (revision 61900) @@ -6191,7 +6191,6 @@ parser_heredoc_identifier(struct parser_ https://github.com/ruby/ruby/blob/trunk/parse.y#L6191 break; } - p->tokenbuf[0] = p->tokenbuf[0] + toklen() - 2; tokfix(); dispatch_scan_event(tHEREDOC_BEG); len = p->lex.pcur - p->lex.pbeg; @@ -9155,7 +9154,7 @@ void https://github.com/ruby/ruby/blob/trunk/parse.y#L9154 rb_parser_set_location_from_strterm_heredoc(struct parser_params *p, rb_strterm_heredoc_t *here, YYLTYPE *yylloc) { const char *eos = RSTRING_PTR(here->term); - int term_len = (int)eos[0]; + long term_len = RSTRING_LEN(here->term) - 2 + (unsigned char)eos[0]; yylloc->beg_pos.lineno = (int)here->sourceline; yylloc->beg_pos.column = (int)(here->u3.lastidx - term_len); -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/