Skip to content

Commit caf5e8a

Browse files
authored
Solve C4267 warnings in win32/ioutil for x64 (GH-17674)
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] <https://learn.microsoft.com/en-us/cpp/error-messages/compiler-warnings/compiler-warning-level-3-c4267>
1 parent 6ae1209 commit caf5e8a

File tree

2 files changed

+7
-5
lines changed

2 files changed

+7
-5
lines changed

win32/ioutil.c

+3-2
Original file line numberDiff line numberDiff line change
@@ -281,7 +281,8 @@ PW32IO int php_win32_ioutil_close(int fd)
281281

282282
PW32IO int php_win32_ioutil_mkdir_w(const wchar_t *path, mode_t mode)
283283
{/*{{{*/
284-
size_t path_len, dir_len = 0;
284+
size_t path_len;
285+
DWORD dir_len = 0;
285286
const wchar_t *my_path;
286287

287288
if (!path) {
@@ -336,7 +337,7 @@ PW32IO int php_win32_ioutil_mkdir_w(const wchar_t *path, mode_t mode)
336337
dst = _tmp + PHP_WIN32_IOUTIL_LONG_PATH_PREFIX_LENW;
337338
#ifndef ZTS
338339
if (dir_len > 0) {
339-
size_t len = GetCurrentDirectoryW(dir_len, dst);
340+
DWORD len = GetCurrentDirectoryW(dir_len, dst);
340341
if (len == 0 || len + 1 != dir_len) {
341342
free(tmp);
342343
free(_tmp);

win32/ioutil.h

+4-3
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,8 @@ PW32IO php_win32_ioutil_normalization_result php_win32_ioutil_normalize_path_w(w
175175
zend_always_inline static wchar_t *php_win32_ioutil_conv_any_to_w(const char* in, size_t in_len, size_t *out_len)
176176
{/*{{{*/
177177
wchar_t *mb, *ret;
178-
size_t mb_len, dir_len = 0;
178+
size_t mb_len;
179+
DWORD dir_len = 0;
179180

180181
mb = php_win32_cp_conv_any_to_w(in, in_len, &mb_len);
181182
if (!mb) {
@@ -227,8 +228,8 @@ zend_always_inline static wchar_t *php_win32_ioutil_conv_any_to_w(const char* in
227228
memcpy(ret, PHP_WIN32_IOUTIL_LONG_PATH_PREFIXW, PHP_WIN32_IOUTIL_LONG_PATH_PREFIX_LENW * sizeof(wchar_t));
228229
#ifndef ZTS
229230
if (dir_len > 0) {
230-
size_t len = GetCurrentDirectoryW(dir_len, dst);
231-
if (len == 0 || len + 1 != dir_len) {
231+
DWORD len = GetCurrentDirectoryW(dir_len, dst);
232+
if (len == 0 || len != dir_len - 1) {
232233
free(ret);
233234
free(mb);
234235
return NULL;

0 commit comments

Comments
 (0)