Shouldn't Zlib::GzipReader#read return "" when you try to read 0 bytes?
At the moment it returns nil, which differs in behaviour to IO#read.
This wouldn't normally matter, but Marshal sometimes tries to read 0
bytes during its work for some reason which I am trying to investigate
(anyone know what circumstances would cause marshal to do that?)
Regards,
Stephen
In article <cenm45$4gg@odak26.prod.google.com>,
"StephenSykes" <jbshaldane@hotmail.com> writes:
Shouldn't Zlib::GzipReader#read return "" when you try to read 0 bytes?
At the moment it returns nil, which differs in behaviour to IO#read.
I think it should be too.
This wouldn't normally matter, but Marshal sometimes tries to read 0
bytes during its work for some reason which I am trying to investigate
(anyone know what circumstances would cause marshal to do that?)
Regards,
Interesting example.
Index: ext/zlib/zlib.c
ยทยทยท
===================================================================
RCS file: /src/ruby/ext/zlib/zlib.c,v
retrieving revision 1.13
diff -u -p -r1.13 zlib.c
--- ext/zlib/zlib.c 23 Jun 2004 09:19:14 -0000 1.13
+++ ext/zlib/zlib.c 3 Aug 2004 16:13:48 -0000
@@ -2075,7 +2075,10 @@ gzfile_read(gz, len)
{
VALUE dst;
- if (len <= 0) return Qnil;
+ if (len < 0)
+ rb_raise(rb_eArgError, "negative length %ld given", len);
+ if (len == 0)
+ return rb_str_new(0, 0);
while (!ZSTREAM_IS_FINISHED(&gz->z) && gz->z.buf_filled < len) {
gzfile_read_more(gz);
}
--
Tanaka Akira