ruby-changes:43935
From: nobu <ko1@a...>
Date: Thu, 25 Aug 2016 11:57:46 +0900 (JST)
Subject: [ruby-changes:43935] nobu:r56008 (trunk): win32/file.c: use ALLOC_N
nobu 2016-08-25 11:57:41 +0900 (Thu, 25 Aug 2016) New Revision: 56008 https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=56008 Log: win32/file.c: use ALLOC_N * win32/file.c (home_dir, replace_to_long_name): use ALLOC_N instead of casted xmalloc with multiplication. win32/file.c (rb_file_expand_path_internal): ditto. Modified files: trunk/win32/file.c Index: win32/file.c =================================================================== --- win32/file.c (revision 56007) +++ win32/file.c (revision 56008) @@ -86,7 +86,7 @@ home_dir(void) https://github.com/ruby/ruby/blob/trunk/win32/file.c#L86 if (!home_type) return NULL; /* allocate buffer */ - buffer = (wchar_t *)xmalloc(buffer_len * sizeof(wchar_t)); + buffer = ALLOC_N(wchar_t, buffer_len); switch (home_type) { case ENV_HOME: @@ -254,7 +254,7 @@ replace_to_long_name(wchar_t **wfullpath https://github.com/ruby/ruby/blob/trunk/win32/file.c#L254 FindClose(find_handle); size = trail_pos + file_len; if (size > (buffer_size ? buffer_size-1 : oldsize)) { - wchar_t *buf = (wchar_t *)xmalloc((size + 1) * sizeof(wchar_t)); + wchar_t *buf = ALLOC_N(wchar_t, (size + 1)); wcsncpy(buf, *wfullpath, trail_pos); if (!buffer_size) xfree(*wfullpath); @@ -526,7 +526,7 @@ rb_file_expand_path_internal(VALUE fname https://github.com/ruby/ruby/blob/trunk/win32/file.c#L526 buffer_len = wpath_len + 1 + wdir_len + 1 + whome_len + 1; - buffer = buffer_pos = (wchar_t *)xmalloc((buffer_len + 1) * sizeof(wchar_t)); + buffer = buffer_pos = ALLOC_N(wchar_t, (buffer_len + 1)); /* add home */ if (whome_len) { @@ -583,7 +583,7 @@ rb_file_expand_path_internal(VALUE fname https://github.com/ruby/ruby/blob/trunk/win32/file.c#L583 size = GetFullPathNameW(buffer, PATH_BUFFER_SIZE, wfullpath_buffer, NULL); if (size > PATH_BUFFER_SIZE) { /* allocate more memory than alloted originally by PATH_BUFFER_SIZE */ - wfullpath = (wchar_t *)xmalloc(size * sizeof(wchar_t)); + wfullpath = ALLOC_N(wchar_t, size); size = GetFullPathNameW(buffer, size, wfullpath, NULL); } else { -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/