[前][次][番号順一覧][スレッド一覧]

ruby-changes:38989

From: usa <ko1@a...>
Date: Tue, 30 Jun 2015 18:39:13 +0900 (JST)
Subject: [ruby-changes:38989] usa:r51070 (trunk): * win32/file.c (rb_freopen): need to terminate by NUL.

usa	2015-06-30 18:38:51 +0900 (Tue, 30 Jun 2015)

  New Revision: 51070

  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=51070

  Log:
    * win32/file.c (rb_freopen): need to terminate by NUL.

  Modified files:
    trunk/ChangeLog
    trunk/win32/file.c
Index: ChangeLog
===================================================================
--- ChangeLog	(revision 51069)
+++ ChangeLog	(revision 51070)
@@ -1,3 +1,7 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1
+Tue Jun 30 18:38:16 2015  NAKAMURA Usaku  <usa@r...>
+
+	* win32/file.c (rb_freopen): need to terminate by NUL.
+
 Tue Jun 30 17:28:25 2015  Nobuyoshi Nakada  <nobu@r...>
 
 	* io.c (rb_io_reopen): freopen(3) with OS encoding path.
Index: win32/file.c
===================================================================
--- win32/file.c	(revision 51069)
+++ win32/file.c	(revision 51070)
@@ -725,11 +725,13 @@ int https://github.com/ruby/ruby/blob/trunk/win32/file.c#L725
 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 https://github.com/ruby/ruby/blob/trunk/win32/file.c#L739
     {
 	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);

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]