diff options
Diffstat (limited to 'deps/uv/src/win/util.c')
-rw-r--r-- | deps/uv/src/win/util.c | 27 |
1 files changed, 22 insertions, 5 deletions
diff --git a/deps/uv/src/win/util.c b/deps/uv/src/win/util.c index c9ca773df7..32a82fa051 100644 --- a/deps/uv/src/win/util.c +++ b/deps/uv/src/win/util.c @@ -163,12 +163,12 @@ int uv_exepath(char* buffer, size_t* size_ptr) { } -int uv_cwd(char* buffer, size_t size) { +int uv_cwd(char* buffer, size_t* size) { DWORD utf16_len; WCHAR utf16_buffer[MAX_PATH]; int r; - if (buffer == NULL || size == 0) { + if (buffer == NULL || size == NULL) { return UV_EINVAL; } @@ -192,19 +192,36 @@ int uv_cwd(char* buffer, size_t size) { utf16_buffer[utf16_len] = L'\0'; } + /* Check how much space we need */ + r = WideCharToMultiByte(CP_UTF8, + 0, + utf16_buffer, + -1, + NULL, + 0, + NULL, + NULL); + if (r == 0) { + return uv_translate_sys_error(GetLastError()); + } else if (r > (int) *size) { + *size = r; + return UV_ENOBUFS; + } + /* Convert to UTF-8 */ r = WideCharToMultiByte(CP_UTF8, 0, utf16_buffer, -1, buffer, - size > INT_MAX ? INT_MAX : (int) size, + *size > INT_MAX ? INT_MAX : (int) *size, NULL, NULL); if (r == 0) { return uv_translate_sys_error(GetLastError()); } + *size = r; return 0; } @@ -323,7 +340,7 @@ int uv_parent_pid() { int parent_pid = -1; HANDLE handle; PROCESSENTRY32 pe; - int current_pid = GetCurrentProcessId(); + DWORD current_pid = GetCurrentProcessId(); pe.dwSize = sizeof(PROCESSENTRY32); handle = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0); @@ -638,7 +655,7 @@ int uv_cpu_info(uv_cpu_info_t** cpu_infos_ptr, int* cpu_count_ptr) { DWORD cpu_speed_size = sizeof(cpu_speed); WCHAR cpu_brand[256]; DWORD cpu_brand_size = sizeof(cpu_brand); - int len; + size_t len; len = _snwprintf(key_name, ARRAY_SIZE(key_name), |