summaryrefslogtreecommitdiff
path: root/dir.c
diff options
context:
space:
mode:
authornagachika <nagachika@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2015-05-19 17:23:27 +0000
committernagachika <nagachika@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2015-05-19 17:23:27 +0000
commit7d7aec241381d11317c16115f6592a0d3c6b7fce (patch)
tree083a5fdf401d5d1e4daf0fe63b941e86883d8224 /dir.c
parent39b89ceeb4a875f12ed90278d291f5ea9135f35a (diff)
merge revision(s) 49859,49861,49865: [Backport #10941] [Backport #10978] [Backport #11089]
* dir.c (replace_real_basename): shouldn't create Ruby object before the object system is loaded. [ruby-core:68430] [Bug #10941] * dir.c (replace_real_basename): need to check the return value of GLOB_REALLOC(). git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_2_2@50545 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'dir.c')
-rw-r--r--dir.c34
1 files changed, 28 insertions, 6 deletions
diff --git a/dir.c b/dir.c
index 0903ec8a14..c8c88a7339 100644
--- a/dir.c
+++ b/dir.c
@@ -1481,12 +1481,34 @@ replace_real_basename(char *path, long base, rb_encoding *enc, int norm_p)
free(wplain);
if (h == INVALID_HANDLE_VALUE) return path;
FindClose(h);
- tmp = rb_w32_conv_from_wchar(fd.cFileName, enc);
- wlen = RSTRING_LEN(tmp);
- path = GLOB_REALLOC(path, base + wlen + 1);
- memcpy(path + base, RSTRING_PTR(tmp), wlen);
- path[base + wlen] = 0;
- rb_str_resize(tmp, 0);
+ if (tmp) {
+ char *buf;
+ tmp = rb_w32_conv_from_wchar(fd.cFileName, enc);
+ wlen = RSTRING_LEN(tmp);
+ buf = GLOB_REALLOC(path, base + wlen + 1);
+ if (buf) {
+ path = buf;
+ memcpy(path + base, RSTRING_PTR(tmp), wlen);
+ path[base + wlen] = 0;
+ }
+ rb_str_resize(tmp, 0);
+ }
+ else {
+ char *utf8filename;
+ wlen = WideCharToMultiByte(CP_UTF8, 0, fd.cFileName, -1, NULL, 0, NULL, NULL);
+ utf8filename = GLOB_REALLOC(0, wlen);
+ if (utf8filename) {
+ char *buf;
+ WideCharToMultiByte(CP_UTF8, 0, fd.cFileName, -1, utf8filename, wlen, NULL, NULL);
+ buf = GLOB_REALLOC(path, base + wlen + 1);
+ if (buf) {
+ path = buf;
+ memcpy(path + base, utf8filename, wlen);
+ path[base + wlen] = 0;
+ }
+ GLOB_FREE(utf8filename);
+ }
+ }
return path;
}
#elif USE_NAME_ON_FS == 1