summaryrefslogtreecommitdiff
path: root/ext/stringio/stringio.c
diff options
context:
space:
mode:
Diffstat (limited to 'ext/stringio/stringio.c')
-rw-r--r--ext/stringio/stringio.c6
1 files changed, 3 insertions, 3 deletions
diff --git a/ext/stringio/stringio.c b/ext/stringio/stringio.c
index 7514264f6a..a525dff235 100644
--- a/ext/stringio/stringio.c
+++ b/ext/stringio/stringio.c
@@ -1168,7 +1168,7 @@ strio_read(int argc, VALUE *argv, VALUE self)
{
struct StringIO *ptr = readable(StringIO(self));
VALUE str = Qnil;
- long len, olen;
+ long len;
switch (argc) {
case 2:
@@ -1177,7 +1177,7 @@ strio_read(int argc, VALUE *argv, VALUE self)
rb_str_modify(str);
case 1:
if (!NIL_P(argv[0])) {
- len = olen = NUM2LONG(argv[0]);
+ len = NUM2LONG(argv[0]);
if (len < 0) {
rb_raise(rb_eArgError, "negative length %ld given", len);
}
@@ -1189,7 +1189,6 @@ strio_read(int argc, VALUE *argv, VALUE self)
}
/* fall through */
case 0:
- olen = -1;
len = RSTRING_LEN(ptr->string);
if (len <= ptr->pos) {
if (NIL_P(str)) {
@@ -1209,6 +1208,7 @@ strio_read(int argc, VALUE *argv, VALUE self)
}
if (NIL_P(str)) {
str = strio_substr(ptr, ptr->pos, len);
+ if (argc > 0) rb_enc_associate(str, rb_ascii8bit_encoding());
}
else {
long rest = RSTRING_LEN(ptr->string) - ptr->pos;