summaryrefslogtreecommitdiff
path: root/parse.y
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2008-03-18 07:24:55 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2008-03-18 07:24:55 +0000
commit91a761b4d0929a5055945ccca4797ff57353cac0 (patch)
treecd93e0bcdc75858ed88a62f8b4fcc355b33fc67a /parse.y
parente58adeae0f384a562bbcb295b0a25026842625ca (diff)
* parse.y (literal_concat_gen): bail out at different encoding.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@15793 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'parse.y')
-rw-r--r--parse.y16
1 files changed, 13 insertions, 3 deletions
diff --git a/parse.y b/parse.y
index e1c047029b..33aba9b6fa 100644
--- a/parse.y
+++ b/parse.y
@@ -7465,15 +7465,19 @@ list_concat_gen(struct parser_params *parser, NODE *head, NODE *tail)
return head;
}
-static void
+static int
literal_concat0(struct parser_params *parser, VALUE head, VALUE tail)
{
if (!rb_enc_compatible(head, tail)) {
compile_error(PARSER_ARG "string literal encodings differ (%s / %s)",
rb_enc_name(rb_enc_get(head)),
rb_enc_name(rb_enc_get(tail)));
+ rb_str_resize(head, 0);
+ rb_str_resize(tail, 0);
+ return 0;
}
rb_str_buf_append(head, tail);
+ return 1;
}
/* concat two string literals */
@@ -7493,7 +7497,12 @@ literal_concat_gen(struct parser_params *parser, NODE *head, NODE *tail)
switch (nd_type(tail)) {
case NODE_STR:
if (htype == NODE_STR) {
- literal_concat0(parser, head->nd_lit, tail->nd_lit);
+ if (!literal_concat0(parser, head->nd_lit, tail->nd_lit)) {
+ error:
+ rb_gc_force_recycle((VALUE)head);
+ rb_gc_force_recycle((VALUE)tail);
+ return 0;
+ }
rb_gc_force_recycle((VALUE)tail);
}
else {
@@ -7503,7 +7512,8 @@ literal_concat_gen(struct parser_params *parser, NODE *head, NODE *tail)
case NODE_DSTR:
if (htype == NODE_STR) {
- literal_concat0(parser, head->nd_lit, tail->nd_lit);
+ if (!literal_concat0(parser, head->nd_lit, tail->nd_lit))
+ goto error;
tail->nd_lit = head->nd_lit;
rb_gc_force_recycle((VALUE)head);
head = tail;