Skip to content

Commit eb4ee49

Browse files
committed
Fix SEGV at unget to a null device StringIO
1 parent 4a35291 commit eb4ee49

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

ext/stringio/stringio.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,9 @@ check_modifiable(struct StringIO *ptr)
180180
else if (OBJ_FROZEN_RAW(ptr->string)) {
181181
rb_raise(rb_eIOError, "not modifiable string");
182182
}
183-
rb_str_modify(ptr->string);
183+
else {
184+
rb_str_modify(ptr->string);
185+
}
184186
}
185187

186188
static VALUE

test/stringio/test_stringio.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,10 @@ def test_null
6464
assert_nil io.gets
6565
io.puts "abc"
6666
assert_nil io.string
67+
68+
# Null device StringIO just drop ungot string
69+
io.ungetc '#'
70+
assert_nil io.getc
6771
end
6872

6973
def test_truncate

0 commit comments

Comments
 (0)