ruby-changes:39388
From: nobu <ko1@a...>
Date: Sun, 2 Aug 2015 14:15:18 +0900 (JST)
Subject: [ruby-changes:39388] nobu:r51469 (trunk): win32/file.c: use allocv buffer and API
nobu 2015-08-02 14:15:02 +0900 (Sun, 02 Aug 2015) New Revision: 51469 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=51469 Log: win32/file.c: use allocv buffer and API * win32/file.c (rb_freopen): convert path name into allocv buffer and get rid of conversion failure in the case non-terminated string. [ruby-core:69780] [Bug #11320] Modified files: trunk/win32/file.c Index: win32/file.c =================================================================== --- win32/file.c (revision 51468) +++ win32/file.c (revision 51469) @@ -729,13 +729,18 @@ int https://github.com/ruby/ruby/blob/trunk/win32/file.c#L729 rb_freopen(VALUE fname, const char *mode, FILE *file) { WCHAR *wname, wmode[4]; + VALUE wtmp; + char *name; 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)) + 1, &len); - wname[len - 1] = L'\0'; + RSTRING_GETMEM(fname, name, len); + n = rb_long2int(len); + len = MultiByteToWideChar(CP_UTF8, 0, name, n, NULL, 0); + wname = ALLOCV_N(WCHAR, wtmp, len + 1); + len = MultiByteToWideChar(CP_UTF8, 0, name, n, wname, len); + wname[len] = L'\0'; RB_GC_GUARD(fname); #if RUBY_MSVCRT_VERSION < 80 && !defined(HAVE__WFREOPEN_S) e = _wfreopen(wname, wmode, file) ? 0 : errno; @@ -745,7 +750,7 @@ rb_freopen(VALUE fname, const char *mode https://github.com/ruby/ruby/blob/trunk/win32/file.c#L750 e = _wfreopen_s(&newfp, wname, wmode, file); } #endif - free(wname); + ALLOCV_END(wtmp); return e; } -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/