diff options
author | Nobuyoshi Nakada <[email protected]> | 2025-02-21 19:40:58 +0900 |
---|---|---|
committer | git <[email protected]> | 2025-02-21 12:06:19 +0000 |
commit | 7ef9110b1eaefbcbf72f25ad941c2c3b7ed3db01 (patch) | |
tree | 2e5994b95ad0290cb0e2f52c5e6205f1b702b48e | |
parent | fa6b9f75efa8411829aa987b81b9c5ca0e081462 (diff) |
[ruby/stringio] Fix SEGV at unget to a null device StringIO
https://github.com/ruby/stringio/commit/eb4ee49218
-rw-r--r-- | ext/stringio/stringio.c | 4 | ||||
-rw-r--r-- | test/stringio/test_stringio.rb | 4 |
2 files changed, 7 insertions, 1 deletions
diff --git a/ext/stringio/stringio.c b/ext/stringio/stringio.c index aa6fbf0cac..0c0f63aac7 100644 --- a/ext/stringio/stringio.c +++ b/ext/stringio/stringio.c @@ -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 diff --git a/test/stringio/test_stringio.rb b/test/stringio/test_stringio.rb index ffaa2efa0a..570b3d7ad6 100644 --- a/test/stringio/test_stringio.rb +++ b/test/stringio/test_stringio.rb @@ -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 |