From 39080991ab143d36afd40f3f6f547de571f98df7 Mon Sep 17 00:00:00 2001 From: matz Date: Mon, 22 Nov 2004 15:29:52 +0000 Subject: * file.c (rb_file_chown): integer conversion should be prior to GetOpenFile(). [ruby-dev:24947] * file.c (rb_file_truncate): ditto. * file.c (rb_file_s_truncate): ditto. * dir.c (dir_seek): use NUM2OFFT(). * misc/ruby-mode.el (ruby-non-block-do-re): [ruby-core:03719] * dir.c (dir_seek): should retrieve dir_data after NUM2INT(). [ruby-dev:24941] * string.c (rb_str_splice): should place index wrapping after possible modification. [ruby-dev:24940] * eval.c (error_print): nicer traceback at interrupt. [ruby-core:03774] * string.c (str_gsub): internal buffer should not be listed by ObjectSpace.each_object() by String#gsub. [ruby-dev:24931] * lib/cgi/session.rb (CGI::Session::FileStore::initialize): raise exception if data corresponding to session specified from the client does not exist. * string.c (str_gsub): internal buffer should not be listed by ObjectSpace.each_object(). [ruby-dev:24919] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_1_8@7354 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- file.c | 24 +++++++++++++++++------- 1 file changed, 17 insertions(+), 7 deletions(-) (limited to 'file.c') diff --git a/file.c b/file.c index 066745ca6a..c1f26ab692 100644 --- a/file.c +++ b/file.c @@ -1744,15 +1744,18 @@ rb_file_chown(obj, owner, group) VALUE obj, owner, group; { OpenFile *fptr; + int o, g; rb_secure(2); GetOpenFile(obj, fptr); + o = NUM2INT(owner); + g = NUM2INT(group); #if defined(DJGPP) || defined(__CYGWIN32__) || defined(_WIN32) || defined(__EMX__) if (!fptr->path) return Qnil; - if (chown(fptr->path, NUM2INT(owner), NUM2INT(group)) == -1) + if (chown(fptr->path, o, g) == -1) rb_sys_fail(fptr->path); #else - if (fchown(fileno(fptr->f), NUM2INT(owner), NUM2INT(group)) == -1) + if (fchown(fileno(fptr->f), o, g) == -1) rb_sys_fail(fptr->path); #endif @@ -2804,11 +2807,14 @@ static VALUE rb_file_s_truncate(klass, path, len) VALUE klass, path, len; { + off_t pos; + rb_secure(2); + pos = NUM2OFFT(len); SafeStringValue(path); #ifdef HAVE_TRUNCATE - if (truncate(StringValueCStr(path), NUM2OFFT(len)) < 0) + if (truncate(StringValueCStr(path), pos) < 0) rb_sys_fail(RSTRING(path)->ptr); #else # ifdef HAVE_CHSIZE @@ -2824,7 +2830,7 @@ rb_file_s_truncate(klass, path, len) rb_sys_fail(RSTRING(path)->ptr); } # endif - if (chsize(tmpfd, NUM2OFFT(len)) < 0) { + if (chsize(tmpfd, pos) < 0) { close(tmpfd); rb_sys_fail(RSTRING(path)->ptr); } @@ -2857,8 +2863,10 @@ rb_file_truncate(obj, len) { OpenFile *fptr; FILE *f; + off_t pos; rb_secure(2); + pos = NUM2OFFT(len); GetOpenFile(obj, fptr); if (!(fptr->mode & FMODE_WRITABLE)) { rb_raise(rb_eIOError, "not opened for writing"); @@ -2867,11 +2875,11 @@ rb_file_truncate(obj, len) fflush(f); fseeko(f, (off_t)0, SEEK_CUR); #ifdef HAVE_TRUNCATE - if (ftruncate(fileno(f), NUM2OFFT(len)) < 0) + if (ftruncate(fileno(f), pos) < 0) rb_sys_fail(fptr->path); #else # ifdef HAVE_CHSIZE - if (chsize(fileno(f), NUM2OFFT(len)) < 0) + if (chsize(fileno(f), pos) < 0) rb_sys_fail(fptr->path); # else rb_notimplement(); @@ -2958,15 +2966,17 @@ rb_file_flock(obj, operation) { #ifndef __CHECKER__ OpenFile *fptr; + int op; rb_secure(2); + op = NUM2INT(operation); GetOpenFile(obj, fptr); if (fptr->mode & FMODE_WRITABLE) { fflush(GetWriteFile(fptr)); } retry: - if (flock(fileno(fptr->f), NUM2INT(operation)) < 0) { + if (flock(fileno(fptr->f), op) < 0) { switch (errno) { case EAGAIN: case EACCES: -- cgit v1.2.3