Skip to content

Commit

Permalink
Fix nested empty heredoc causing segfault
Browse files Browse the repository at this point in the history
  • Loading branch information
bouk committed Nov 24, 2016
1 parent a630c4f commit 73e4f06
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 2 deletions.
6 changes: 5 additions & 1 deletion mrbgems/mruby-compiler/core/codegen.c
Original file line number Diff line number Diff line change
Expand Up @@ -2285,7 +2285,11 @@ codegen(codegen_scope *s, node *tree, int val)
if (val) {
node *n = tree;

if (!n) break;
if (!n) {
genop(s, MKOP_A(OP_LOADNIL, cursp()));
push();
break;
}
codegen(s, n->car, VAL);
n = n->cdr;
while (n) {
Expand Down
2 changes: 1 addition & 1 deletion mrbgems/mruby-compiler/core/parse.y
Original file line number Diff line number Diff line change
Expand Up @@ -6541,7 +6541,7 @@ mrb_parser_dump(mrb_state *mrb, node *tree, int offset)

case NODE_HEREDOC:
printf("NODE_HEREDOC (<<%s):\n", ((parser_heredoc_info*)tree)->term);
mrb_parser_dump(mrb, ((parser_heredoc_info*)tree)->doc, offset+1);
dump_recur(mrb, ((parser_heredoc_info*)tree)->doc, offset+1);
break;

default:
Expand Down
10 changes: 10 additions & 0 deletions test/t/codegen.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
##
# Codegen tests

assert('nested empty heredoc') do
_, a = nil, <<B
#{<<A}
A
B
assert_equal "\n", a
end

0 comments on commit 73e4f06

Please sign in to comment.