1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

* io.c (rb_file_open_internal, rb_io_reopen): fname might be altered

while GC.  [ruby-dev:24408]


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@6995 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
nobu 2004-10-04 05:04:22 +00:00
parent 2547b0c073
commit 889a620b76
2 changed files with 17 additions and 9 deletions

View file

@ -1,3 +1,8 @@
Mon Oct 4 14:03:40 2004 Nobuyoshi Nakada <nobu@ruby-lang.org>
* io.c (rb_file_open_internal, rb_io_reopen): fname might be altered
while GC. [ruby-dev:24408]
Mon Oct 4 12:53:45 2004 Hidetoshi NAGAI <nagai@ai.kyutech.ac.jp>
* ext/tk/lib/tk/optiondb.rb: support definition of command

21
io.c
View file

@ -2421,6 +2421,8 @@ rb_io_mode_modenum(mode)
return flags;
}
#define MODENUM_MAX 4
static char*
rb_io_modenum_mode(flags, mode)
int flags;
@ -2548,12 +2550,13 @@ rb_file_open_internal(io, fname, mode)
const char *fname, *mode;
{
OpenFile *fptr;
char mbuf[MODENUM_MAX];
MakeOpenFile(io, fptr);
fptr->mode = rb_io_mode_flags(mode);
fptr->f = rb_fopen(fname, mode);
fptr->path = strdup(fname);
fptr->f = rb_fopen(fptr->path, rb_io_flags_mode(fptr->mode, mbuf));
return io;
}
@ -2574,7 +2577,7 @@ rb_file_sysopen_internal(io, fname, flags, mode)
OpenFile *fptr;
int fd;
char *m;
char mbuf[4];
char mbuf[MODENUM_MAX];
MakeOpenFile(io, fptr);
@ -2878,7 +2881,7 @@ rb_io_popen(str, argc, argv, klass)
{
char *mode;
VALUE pname, pmode, port;
char mbuf[4];
char mbuf[MODENUM_MAX];
if (rb_scan_args(argc, argv, "11", &pname, &pmode) == 1) {
mode = "r";
@ -2965,7 +2968,7 @@ rb_io_s_popen(argc, argv, klass)
{
char *mode;
VALUE pname, pmode, port, tmp;
char mbuf[4];
char mbuf[MODENUM_MAX];
if (rb_scan_args(argc, argv, "11", &pname, &pmode) == 1) {
mode = "r";
@ -3353,7 +3356,7 @@ rb_io_reopen(argc, argv, file)
VALUE file;
{
VALUE fname, nmode;
char *mode;
char mode[MODENUM_MAX];
OpenFile *fptr;
rb_secure(4);
@ -3373,10 +3376,10 @@ rb_io_reopen(argc, argv, file)
}
if (!NIL_P(nmode)) {
mode = StringValuePtr(nmode);
strncpy(mode, StringValuePtr(nmode), sizeof(mode));
mode[sizeof(mode) - 1] = 0;
}
else {
mode = ALLOCA_N(char, 4);
rb_io_flags_mode(fptr->mode, mode);
}
@ -3388,7 +3391,7 @@ rb_io_reopen(argc, argv, file)
fptr->path = strdup(RSTRING(fname)->ptr);
fptr->mode = rb_io_mode_flags(mode);
if (!fptr->f) {
fptr->f = rb_fopen(RSTRING(fname)->ptr, mode);
fptr->f = rb_fopen(fptr->path, mode);
if (fptr->f2) {
fclose(fptr->f2);
fptr->f2 = 0;
@ -3948,7 +3951,7 @@ rb_io_initialize(argc, argv, io)
VALUE fnum, mode, orig;
OpenFile *fp, *ofp = NULL;
int fd, flags, fmode;
char mbuf[4];
char mbuf[MODENUM_MAX];
rb_secure(4);
rb_scan_args(argc, argv, "11", &fnum, &mode);