From ea40e83840a6467d004bd386633b204aaebc2f51 Mon Sep 17 00:00:00 2001 From: "Christoph M. Becker" Date: Tue, 15 Nov 2022 15:37:32 +0100 Subject: [PATCH] Avoid undefined behavior in Windows ftok(3) emulation `.nFileIndexHigh` is a unsigned 32bit number. Casting that to `__int64` and shifting left by 32bits triggers undefined behavior if the most significant bit of `.nFileIndexHigh` is set. We could avoid that by casting to `(__uint64)`, but in that case the whole clause doesn't have an effect anymore, so we drop it altogether. --- win32/ftok.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/win32/ftok.c b/win32/ftok.c index 3a545375fa0a6..76e47ec48e1aa 100644 --- a/win32/ftok.c +++ b/win32/ftok.c @@ -51,7 +51,7 @@ ftok(const char *pathname, int proj_id) return (key_t)-1; } - ret = (key_t) ((proj_id & 0xff) << 24 | (st.st_dev & 0xff) << 16 | ((bhfi.nFileIndexLow | (__int64)bhfi.nFileIndexHigh << 32) & 0xffff)); + ret = (key_t) ((proj_id & 0xff) << 24 | (st.st_dev & 0xff) << 16 | (bhfi.nFileIndexLow & 0xffff)); CloseHandle(fh); PHP_WIN32_IOUTIL_CLEANUP_W()