summaryrefslogtreecommitdiff
path: root/encoding.c
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2013-07-12 07:28:40 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2013-07-12 07:28:40 +0000
commit8b8cce322b3ddaa4d2449215224110e8367b1854 (patch)
treeb38605c21163db9a1fc279a92643924fd4ef8cb8 /encoding.c
parentbc241235ac4d02638dfe56d2d87b8cb906400f9d (diff)
encoding.c: refill terminator at associating encoding
* encoding.c (rb_enc_associate_index): refill the terminator if it becomes longer than before. [ruby-dev:47500] [Bug #8624] * string.c (str_null_char, str_fill_term): get rid of out of bound access. * string.c (rb_str_fill_terminator): add a parameter for the length of new terminator. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@41930 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'encoding.c')
-rw-r--r--encoding.c9
1 files changed, 8 insertions, 1 deletions
diff --git a/encoding.c b/encoding.c
index 869c1b0acd..7c64248d12 100644
--- a/encoding.c
+++ b/encoding.c
@@ -777,10 +777,12 @@ VALUE
rb_enc_associate_index(VALUE obj, int idx)
{
rb_encoding *enc;
+ int oldidx, oldtermlen, termlen;
/* enc_check_capable(obj);*/
rb_check_frozen(obj);
- if (rb_enc_get_index(obj) == idx)
+ oldidx = rb_enc_get_index(obj);
+ if (oldidx == idx)
return obj;
if (SPECIAL_CONST_P(obj)) {
rb_raise(rb_eArgError, "cannot set encoding");
@@ -790,6 +792,11 @@ rb_enc_associate_index(VALUE obj, int idx)
!rb_enc_asciicompat(enc)) {
ENC_CODERANGE_CLEAR(obj);
}
+ termlen = rb_enc_mbminlen(enc);
+ oldtermlen = rb_enc_mbminlen(rb_enc_from_index(oldidx));
+ if (oldtermlen < termlen && RB_TYPE_P(obj, T_STRING)) {
+ rb_str_fill_terminator(obj, oldtermlen);
+ }
enc_set_index(obj, idx);
return obj;
}