From 093d6d33c0c23c4573f87e51af6f9adcfcc8d8ea Mon Sep 17 00:00:00 2001 From: nobu Date: Tue, 30 Nov 2004 14:38:26 +0000 Subject: * io.c (io_fread): need not to null terminate. [ruby-dev:24998] * io.c (read_all): remove unnecessary rb_str_resize(). [ruby-dev:24996] (backported from CVS HEAD) * io.c (io_readpartial): ditto. * io.c (io_read): ditto. git-svn-id: http://svn.ruby-lang.org/repos/ruby/branches/ruby_1_8@7426 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- ChangeLog | 11 +++++++++++ io.c | 13 ++++++------- 2 files changed, 17 insertions(+), 7 deletions(-) diff --git a/ChangeLog b/ChangeLog index f9e87ee9c..51e686a28 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,14 @@ +Tue Nov 30 23:38:18 2004 Nobuyoshi Nakada + + * io.c (io_fread): need not to null terminate. [ruby-dev:24998] + + * io.c (read_all): remove unnecessary rb_str_resize(). + [ruby-dev:24996] (backported from CVS HEAD) + + * io.c (io_readpartial): ditto. + + * io.c (io_read): ditto. + Mon Nov 29 16:06:04 2004 Nobuyoshi Nakada * ext/stringio/stringio.c (strio_write): insufficiently filled string diff --git a/io.c b/io.c index ba7f4b08e..04e8d572b 100644 --- a/io.c +++ b/io.c @@ -988,7 +988,6 @@ io_fread(ptr, len, fptr) } if (len == n) return 0; } - *ptr = '\0'; break; } *ptr++ = c; @@ -1064,7 +1063,6 @@ read_all(fptr, siz, str) n = io_fread(RSTRING(str)->ptr+bytes, siz-bytes, fptr); rb_str_unlocktmp(str); if (n == 0 && bytes == 0) { - rb_str_resize(str,0); if (!fptr->f) break; if (feof(fptr->f)) break; if (!ferror(fptr->f)) break; @@ -1140,11 +1138,14 @@ io_read(argc, argv, io) n = io_fread(RSTRING(str)->ptr, len, fptr); rb_str_unlocktmp(str); if (n == 0) { - rb_str_resize(str,0); if (!fptr->f) return Qnil; - if (feof(fptr->f)) return Qnil; + if (feof(fptr->f)) { + rb_str_resize(str, 0); + return Qnil; + } if (len > 0) rb_sys_fail(fptr->path); } + rb_str_resize(str, n); RSTRING(str)->len = n; RSTRING(str)->ptr[n] = '\0'; OBJ_TAINT(str); @@ -2184,14 +2185,12 @@ rb_io_sysread(argc, argv, io) TRAP_END; if (n == -1) { - rb_str_resize(str, 0); rb_sys_fail(fptr->path); } + rb_str_resize(str, n); if (n == 0 && ilen > 0) { - rb_str_resize(str, 0); rb_eof_error(); } - RSTRING(str)->len = n; RSTRING(str)->ptr[n] = '\0'; OBJ_TAINT(str); -- cgit