* 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:
parent
2547b0c073
commit
889a620b76
@ -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>
|
Mon Oct 4 12:53:45 2004 Hidetoshi NAGAI <nagai@ai.kyutech.ac.jp>
|
||||||
|
|
||||||
* ext/tk/lib/tk/optiondb.rb: support definition of command
|
* ext/tk/lib/tk/optiondb.rb: support definition of command
|
||||||
|
21
io.c
21
io.c
@ -2421,6 +2421,8 @@ rb_io_mode_modenum(mode)
|
|||||||
return flags;
|
return flags;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#define MODENUM_MAX 4
|
||||||
|
|
||||||
static char*
|
static char*
|
||||||
rb_io_modenum_mode(flags, mode)
|
rb_io_modenum_mode(flags, mode)
|
||||||
int flags;
|
int flags;
|
||||||
@ -2548,12 +2550,13 @@ rb_file_open_internal(io, fname, mode)
|
|||||||
const char *fname, *mode;
|
const char *fname, *mode;
|
||||||
{
|
{
|
||||||
OpenFile *fptr;
|
OpenFile *fptr;
|
||||||
|
char mbuf[MODENUM_MAX];
|
||||||
|
|
||||||
MakeOpenFile(io, fptr);
|
MakeOpenFile(io, fptr);
|
||||||
|
|
||||||
fptr->mode = rb_io_mode_flags(mode);
|
fptr->mode = rb_io_mode_flags(mode);
|
||||||
fptr->f = rb_fopen(fname, mode);
|
|
||||||
fptr->path = strdup(fname);
|
fptr->path = strdup(fname);
|
||||||
|
fptr->f = rb_fopen(fptr->path, rb_io_flags_mode(fptr->mode, mbuf));
|
||||||
|
|
||||||
return io;
|
return io;
|
||||||
}
|
}
|
||||||
@ -2574,7 +2577,7 @@ rb_file_sysopen_internal(io, fname, flags, mode)
|
|||||||
OpenFile *fptr;
|
OpenFile *fptr;
|
||||||
int fd;
|
int fd;
|
||||||
char *m;
|
char *m;
|
||||||
char mbuf[4];
|
char mbuf[MODENUM_MAX];
|
||||||
|
|
||||||
MakeOpenFile(io, fptr);
|
MakeOpenFile(io, fptr);
|
||||||
|
|
||||||
@ -2878,7 +2881,7 @@ rb_io_popen(str, argc, argv, klass)
|
|||||||
{
|
{
|
||||||
char *mode;
|
char *mode;
|
||||||
VALUE pname, pmode, port;
|
VALUE pname, pmode, port;
|
||||||
char mbuf[4];
|
char mbuf[MODENUM_MAX];
|
||||||
|
|
||||||
if (rb_scan_args(argc, argv, "11", &pname, &pmode) == 1) {
|
if (rb_scan_args(argc, argv, "11", &pname, &pmode) == 1) {
|
||||||
mode = "r";
|
mode = "r";
|
||||||
@ -2965,7 +2968,7 @@ rb_io_s_popen(argc, argv, klass)
|
|||||||
{
|
{
|
||||||
char *mode;
|
char *mode;
|
||||||
VALUE pname, pmode, port, tmp;
|
VALUE pname, pmode, port, tmp;
|
||||||
char mbuf[4];
|
char mbuf[MODENUM_MAX];
|
||||||
|
|
||||||
if (rb_scan_args(argc, argv, "11", &pname, &pmode) == 1) {
|
if (rb_scan_args(argc, argv, "11", &pname, &pmode) == 1) {
|
||||||
mode = "r";
|
mode = "r";
|
||||||
@ -3353,7 +3356,7 @@ rb_io_reopen(argc, argv, file)
|
|||||||
VALUE file;
|
VALUE file;
|
||||||
{
|
{
|
||||||
VALUE fname, nmode;
|
VALUE fname, nmode;
|
||||||
char *mode;
|
char mode[MODENUM_MAX];
|
||||||
OpenFile *fptr;
|
OpenFile *fptr;
|
||||||
|
|
||||||
rb_secure(4);
|
rb_secure(4);
|
||||||
@ -3373,10 +3376,10 @@ rb_io_reopen(argc, argv, file)
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (!NIL_P(nmode)) {
|
if (!NIL_P(nmode)) {
|
||||||
mode = StringValuePtr(nmode);
|
strncpy(mode, StringValuePtr(nmode), sizeof(mode));
|
||||||
|
mode[sizeof(mode) - 1] = 0;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
mode = ALLOCA_N(char, 4);
|
|
||||||
rb_io_flags_mode(fptr->mode, mode);
|
rb_io_flags_mode(fptr->mode, mode);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -3388,7 +3391,7 @@ rb_io_reopen(argc, argv, file)
|
|||||||
fptr->path = strdup(RSTRING(fname)->ptr);
|
fptr->path = strdup(RSTRING(fname)->ptr);
|
||||||
fptr->mode = rb_io_mode_flags(mode);
|
fptr->mode = rb_io_mode_flags(mode);
|
||||||
if (!fptr->f) {
|
if (!fptr->f) {
|
||||||
fptr->f = rb_fopen(RSTRING(fname)->ptr, mode);
|
fptr->f = rb_fopen(fptr->path, mode);
|
||||||
if (fptr->f2) {
|
if (fptr->f2) {
|
||||||
fclose(fptr->f2);
|
fclose(fptr->f2);
|
||||||
fptr->f2 = 0;
|
fptr->f2 = 0;
|
||||||
@ -3948,7 +3951,7 @@ rb_io_initialize(argc, argv, io)
|
|||||||
VALUE fnum, mode, orig;
|
VALUE fnum, mode, orig;
|
||||||
OpenFile *fp, *ofp = NULL;
|
OpenFile *fp, *ofp = NULL;
|
||||||
int fd, flags, fmode;
|
int fd, flags, fmode;
|
||||||
char mbuf[4];
|
char mbuf[MODENUM_MAX];
|
||||||
|
|
||||||
rb_secure(4);
|
rb_secure(4);
|
||||||
rb_scan_args(argc, argv, "11", &fnum, &mode);
|
rb_scan_args(argc, argv, "11", &fnum, &mode);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user