From e6e84eab64ae594f78d21dbd07ba1d2de57168e3 Mon Sep 17 00:00:00 2001 From: matz Date: Tue, 30 Nov 2004 09:36:39 +0000 Subject: [PATCH] * io.c (io_fread): need not to null terminate. [ruby-dev:24998] * io.c (read_all): remove unnecessary rb_str_resize(). [ruby-dev:24996] * io.c (io_readpartial): ditto. * io.c (io_read): ditto. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@7425 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- ChangeLog | 2 ++ io.c | 14 ++++++-------- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/ChangeLog b/ChangeLog index ee46bde327..20f8fb9654 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,7 @@ Tue Nov 30 16:18:50 2004 Yukihiro Matsumoto + * io.c (io_fread): need not to null terminate. [ruby-dev:24998] + * eval.c (rb_eval): should check previous frame for ZSUPER. * io.c (read_all): remove unnecessary rb_str_resize(). diff --git a/io.c b/io.c index 6fdd9e9466..857a12a614 100644 --- a/io.c +++ b/io.c @@ -1009,7 +1009,6 @@ io_fread(ptr, len, fptr) } if (len == n) return 0; } - *ptr = '\0'; break; } *ptr++ = c; @@ -1086,7 +1085,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; @@ -1203,7 +1201,6 @@ io_readpartial(argc, argv, io) if (n < 0) { if (rb_io_wait_readable(fileno(fptr->f))) goto again; - rb_str_resize(str, 0); rb_sys_fail(fptr->path); } } @@ -1274,11 +1271,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); @@ -2335,14 +2335,12 @@ rb_io_sysread(argc, argv, io) rb_str_unlocktmp(str); 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);