[ruby/stringio] Fix SEGV at unget to a null device StringIO

https://github.com/ruby/stringio/commit/eb4ee49218
This commit is contained in:
Nobuyoshi Nakada 2025-02-21 19:40:58 +09:00 committed by git
parent fa6b9f75ef
commit 7ef9110b1e
2 changed files with 7 additions and 1 deletions

View File

@ -180,7 +180,9 @@ check_modifiable(struct StringIO *ptr)
else if (OBJ_FROZEN_RAW(ptr->string)) {
rb_raise(rb_eIOError, "not modifiable string");
}
rb_str_modify(ptr->string);
else {
rb_str_modify(ptr->string);
}
}
static VALUE

View File

@ -64,6 +64,10 @@ class TestStringIO < Test::Unit::TestCase
assert_nil io.gets
io.puts "abc"
assert_nil io.string
# Null device StringIO just drop ungot string
io.ungetc '#'
assert_nil io.getc
end
def test_truncate