summaryrefslogtreecommitdiff
path: root/win32
diff options
context:
space:
mode:
authorusa <usa@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2015-06-30 09:38:51 +0000
committerusa <usa@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2015-06-30 09:38:51 +0000
commit3e01334faef59760684ddf5904332b927ca8eb33 (patch)
tree50bd59539e3c9bcad29062acbd5631646eb08fd4 /win32
parent93446fedd3ae3efcccdeede1a5af1ec7e8b6d1cd (diff)
* win32/file.c (rb_freopen): need to terminate by NUL.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@51070 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'win32')
-rw-r--r--win32/file.c5
1 files changed, 4 insertions, 1 deletions
diff --git a/win32/file.c b/win32/file.c
index 799810a..99d94fe 100644
--- a/win32/file.c
+++ b/win32/file.c
@@ -725,11 +725,13 @@ int
rb_freopen(VALUE fname, const char *mode, FILE *file)
{
WCHAR *wname, wmode[4];
+ long len;
int e = 0, n = MultiByteToWideChar(CP_ACP, 0, mode, -1, NULL, 0);
if (n > numberof(wmode)) return EINVAL;
MultiByteToWideChar(CP_ACP, 0, mode, -1, wmode, numberof(wmode));
wname = rb_w32_mbstr_to_wstr(CP_UTF8, RSTRING_PTR(fname),
- rb_long2int(RSTRING_LEN(fname)), NULL);
+ rb_long2int(RSTRING_LEN(fname)) + 1, &len);
+ wname[len - 1] = L'\0';
RB_GC_GUARD(fname);
#if RUBY_MSVCRT_VERSION < 80 && !defined(HAVE__WFREOPEN_S)
e = _wfreopen(wname, wmode, file) ? 0 : errno;
@@ -737,6 +739,7 @@ rb_freopen(VALUE fname, const char *mode, FILE *file)
{
FILE *newfp = 0;
e = _wfreopen_s(&newfp, wname, wmode, file);
+ if (e != 0) cprintf("DEBUG: %d [%ls] [%ls]\n", e, wname, wmode);
}
#endif
xfree(wname);