diff options
Diffstat (limited to 'win32')
-rw-r--r-- | win32/file.c | 20 |
1 files changed, 12 insertions, 8 deletions
diff --git a/win32/file.c b/win32/file.c index 897f16e9ef..a5aafa5e77 100644 --- a/win32/file.c +++ b/win32/file.c @@ -33,19 +33,17 @@ replace_wchar(wchar_t *s, int find, int replace) /* Convert str from multibyte char to wchar with specified code page */ static inline void -convert_mb_to_wchar(VALUE str, wchar_t **wstr, wchar_t **wstr_pos, size_t *wstr_len, UINT code_page) +convert_mb_to_wchar(const char *str, wchar_t **wstr, size_t *wstr_len, UINT code_page) { size_t len; - if (NIL_P(str)) + if (!str) return; - len = MultiByteToWideChar(code_page, 0, RSTRING_PTR(str), -1, NULL, 0) + 1; + len = MultiByteToWideChar(code_page, 0, str, -1, NULL, 0) + 1; *wstr = (wchar_t *)xmalloc(len * sizeof(wchar_t)); - if (wstr_pos) - *wstr_pos = *wstr; - MultiByteToWideChar(code_page, 0, RSTRING_PTR(str), -1, *wstr, len); + MultiByteToWideChar(code_page, 0, str, -1, *wstr, len); *wstr_len = len - 2; } @@ -388,7 +386,10 @@ rb_file_expand_path_internal(VALUE fname, VALUE dname, int abs_mode, int long_na } /* convert char * to wchar_t */ - convert_mb_to_wchar(path, &wpath, &wpath_pos, &wpath_len, cp); + if (!NIL_P(path)) { + convert_mb_to_wchar(RSTRING_PTR(path), &wpath, &wpath_len, cp); + wpath_pos = wpath; + } /* determine if we need the user's home directory */ /* expand '~' only if NOT rb_file_absolute_path() where `abs_mode` is 1 */ @@ -453,7 +454,10 @@ rb_file_expand_path_internal(VALUE fname, VALUE dname, int abs_mode, int long_na } /* convert char * to wchar_t */ - convert_mb_to_wchar(dir, &wdir, &wdir_pos, &wdir_len, cp); + if (!NIL_P(dir)) { + convert_mb_to_wchar(RSTRING_PTR(dir), &wdir, &wdir_len, cp); + wdir_pos = wdir; + } if (abs_mode == 0 && wdir_len > 0 && wdir_pos[0] == L'~' && (wdir_len == 1 || IS_DIR_SEPARATOR_P(wdir_pos[1]))) { |