# \[Bug #684\] io.read(nil, buf) $B$G(B buf $B$,JQ99$5$l$J$$(B

**URL:** <https://www.ruby-forum.com/t/bug-684-io-read-nil-buf-b-g-b-buf-b-jq99-5-l-j-b/151809>\
**Category:** Development\
**Created:** [October 26, 2008, 2:26am UTC](https://www.ruby-forum.com/t/bug-684-io-read-nil-buf-b-g-b-buf-b-jq99-5-l-j-b/151809 "2008-10-26T02:26:41Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![SSwanabe](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/d6d6ee/32.png) [@SSwanabe](https://www.ruby-forum.com/u/SSwanabe)\
**Post date:** [October 26, 2008, 2:26am UTC](https://www.ruby-forum.com/t/bug-684-io-read-nil-buf-b-g-b-buf-b-jq99-5-l-j-b/151809/1 "2008-10-26T02:26:41Z")

</div>

Bug #684: io.read(nil, buf) e$B$Ge(B buf e$B$,JQ99$5$l$J$$e(B  
[http://redmine.ruby-lang.org/issues/show/684](http://redmine.ruby-lang.org/issues/show/684)

e$B5/I\<\<Te(B: \_ wanabe  
e$B%9%F!\<%?%9e(B: Open, e$BM%@hEYe(B: Normal

IO#read e$B$NBh0l0z?t$Ke(B  
nile$B!"BhFs0z?t$K=PNO%P%C%U%!MQ$NJ8;zNs$r;XDj$7$?\>l9ge(B  
e$B=PNO%P%C%U%!$,JQ99$5$l$^$;$s!#e(B

$ ruby -ve ’  
r, w = IO.pipe  
w.print “a”  
w.close  
buf = “x”  
p r.read(nil, buf)  
p buf  
’  
ruby 1.9.0 (2008-10-26 revision 19941) [i386-mingw32]  
“a”  
“x”

e$B$3$N$h$&$J46$8$G$I$&$G$7$g$&$+!#e(B

# Index: io.c

— io.c (revision 19941)  
+++ io.c (working copy)  
@@ -1556,7 +1556,12 @@  
int cr;

```
 if (NEED_READCONV(fptr)) {

```

- 

```
   VALUE str = rb_str_new(NULL, 0);

```

- 

```
   if (NIL_P(str)) {

```

- 

```
       str = rb_str_new(NULL, 0);

```

- 

```
   }

```

- 

```
   else {

```

- 

```
       rb_str_resize(str, 0);

```

- 

```
   }
   make_readconv(fptr);
   while (1) {
       if (fptr->cbuf_len) {

```
