From d045629eb6dbd2485e80c6ba6170e3240c7e0c44 Mon Sep 17 00:00:00 2001 From: "Christoph M. Becker" Date: Sun, 2 Feb 2025 18:53:56 +0100 Subject: [PATCH] Solve C4267 warnings in win32/ioutil for x64 C4267[1] are about conversion from `size_t` to a "smaller" type, causing potential loss of data (aka. truncation). In this case we can solve that cleanly (i.e. without casting and further checks) by changing the affected variables to be of type `DWORD`. [1] --- win32/ioutil.c | 5 +++-- win32/ioutil.h | 7 ++++--- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/win32/ioutil.c b/win32/ioutil.c index 3231b92ffc5b0..c9464c9474481 100644 --- a/win32/ioutil.c +++ b/win32/ioutil.c @@ -281,7 +281,8 @@ PW32IO int php_win32_ioutil_close(int fd) PW32IO int php_win32_ioutil_mkdir_w(const wchar_t *path, mode_t mode) {/*{{{*/ - size_t path_len, dir_len = 0; + size_t path_len; + DWORD dir_len = 0; const wchar_t *my_path; if (!path) { @@ -336,7 +337,7 @@ PW32IO int php_win32_ioutil_mkdir_w(const wchar_t *path, mode_t mode) dst = _tmp + PHP_WIN32_IOUTIL_LONG_PATH_PREFIX_LENW; #ifndef ZTS if (dir_len > 0) { - size_t len = GetCurrentDirectoryW(dir_len, dst); + DWORD len = GetCurrentDirectoryW(dir_len, dst); if (len == 0 || len + 1 != dir_len) { free(tmp); free(_tmp); diff --git a/win32/ioutil.h b/win32/ioutil.h index 8b9ed491ffd99..affe7607455b1 100644 --- a/win32/ioutil.h +++ b/win32/ioutil.h @@ -175,7 +175,8 @@ PW32IO php_win32_ioutil_normalization_result php_win32_ioutil_normalize_path_w(w zend_always_inline static wchar_t *php_win32_ioutil_conv_any_to_w(const char* in, size_t in_len, size_t *out_len) {/*{{{*/ wchar_t *mb, *ret; - size_t mb_len, dir_len = 0; + size_t mb_len; + DWORD dir_len = 0; mb = php_win32_cp_conv_any_to_w(in, in_len, &mb_len); if (!mb) { @@ -227,8 +228,8 @@ zend_always_inline static wchar_t *php_win32_ioutil_conv_any_to_w(const char* in memcpy(ret, PHP_WIN32_IOUTIL_LONG_PATH_PREFIXW, PHP_WIN32_IOUTIL_LONG_PATH_PREFIX_LENW * sizeof(wchar_t)); #ifndef ZTS if (dir_len > 0) { - size_t len = GetCurrentDirectoryW(dir_len, dst); - if (len == 0 || len + 1 != dir_len) { + DWORD len = GetCurrentDirectoryW(dir_len, dst); + if (len == 0 || len != dir_len - 1) { free(ret); free(mb); return NULL;