summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--test/ruby/test_encoding.rb12
-rw-r--r--variable.c7
2 files changed, 17 insertions, 2 deletions
diff --git a/test/ruby/test_encoding.rb b/test/ruby/test_encoding.rb
index 282ac6b1ae..6d0665ae93 100644
--- a/test/ruby/test_encoding.rb
+++ b/test/ruby/test_encoding.rb
@@ -65,6 +65,18 @@ class TestEncoding < Test::Unit::TestCase
END;
end
+ def test_extra_encoding
+ assert_separately([], "#{<<~"begin;"}\n#{<<~'end;'}")
+ begin;
+ 200.times {|i|
+ Encoding::UTF_8.replicate("dummy#{i}")
+ }
+ e = Encoding.list.last
+ format = "%d".force_encoding(e)
+ assert_raise(TypeError) {format % 0}
+ end;
+ end
+
def test_dummy_p
assert_equal(true, Encoding::ISO_2022_JP.dummy?)
assert_equal(false, Encoding::UTF_8.dummy?)
diff --git a/variable.c b/variable.c
index 646d60d6eb..2dba76668b 100644
--- a/variable.c
+++ b/variable.c
@@ -1134,9 +1134,12 @@ static st_table *
iv_index_tbl_make(VALUE obj)
{
VALUE klass = rb_obj_class(obj);
- st_table *iv_index_tbl = RCLASS_IV_INDEX_TBL(klass);
+ st_table *iv_index_tbl;
- if (!iv_index_tbl) {
+ if (!klass) {
+ rb_raise(rb_eTypeError, "hidden object cannot have instance variables");
+ }
+ if (!(iv_index_tbl = RCLASS_IV_INDEX_TBL(klass))) {
iv_index_tbl = RCLASS_IV_INDEX_TBL(klass) = st_init_numtable();
}