Commit e1325fa7 authored by brucedawson's avatar brucedawson Committed by Commit bot

Use double cast to avoid VS 2015 64-bit warning

If you convert a 64-bit pointer directly to a 32-bit or smaller integer
then VS 2015 guesses (not unreasonably) that it might be an accidental
pointer truncation. The standard fix is to use a double-cast, to a
pointer-sized integer and then to DWORD.

This fixes a C4311 "pointer truncation" warning introduced by
crrev.com/1225183003

Warning C4312 (conversion from int to ptr of greater size) is suppressed
in this project but adding double-casts for the reverse conversion keeps
the code symmetrical and allows us to enable C4312 in the future.

BUG=440500

Review URL: https://codereview.chromium.org/1684963003

Cr-Commit-Position: refs/heads/master@{#374828}
parent a234a077
...@@ -284,8 +284,8 @@ std::wstring GenerateEventName(DWORD pid) { ...@@ -284,8 +284,8 @@ std::wstring GenerateEventName(DWORD pid) {
// This is the function that is called when testing thread creation. // This is the function that is called when testing thread creation.
// It is expected to set an event that the caller is waiting on. // It is expected to set an event that the caller is waiting on.
DWORD TestThreadFunc(LPVOID lpdwThreadParam) { DWORD TestThreadFunc(LPVOID lpdwThreadParam) {
std::wstring event_name = std::wstring event_name = GenerateEventName(
GenerateEventName(reinterpret_cast<DWORD>(lpdwThreadParam)); static_cast<DWORD>(reinterpret_cast<uintptr_t>(lpdwThreadParam)));
if (!event_name.length()) { if (!event_name.length()) {
return 1; return 1;
} }
...@@ -314,7 +314,8 @@ SBOX_TESTS_COMMAND int Process_CreateThread(int argc, wchar_t** argv) { ...@@ -314,7 +314,8 @@ SBOX_TESTS_COMMAND int Process_CreateThread(int argc, wchar_t** argv) {
DWORD thread_id = 0; DWORD thread_id = 0;
HANDLE thread = NULL; HANDLE thread = NULL;
thread = ::CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)&TestThreadFunc, thread = ::CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)&TestThreadFunc,
reinterpret_cast<LPVOID>(pid), 0, &thread_id); reinterpret_cast<LPVOID>(static_cast<uintptr_t>(pid)),
0, &thread_id);
if (!thread) { if (!thread) {
return SBOX_TEST_THIRD_ERROR; return SBOX_TEST_THIRD_ERROR;
...@@ -499,9 +500,9 @@ TEST(ProcessPolicyTest, TestCreateThreadOutsideSandbox) { ...@@ -499,9 +500,9 @@ TEST(ProcessPolicyTest, TestCreateThreadOutsideSandbox) {
DWORD thread_id = 0; DWORD thread_id = 0;
HANDLE thread = NULL; HANDLE thread = NULL;
thread = TargetCreateThread(::CreateThread, NULL, 0, thread = TargetCreateThread(
(LPTHREAD_START_ROUTINE)&TestThreadFunc, ::CreateThread, NULL, 0, (LPTHREAD_START_ROUTINE)&TestThreadFunc,
reinterpret_cast<LPVOID>(pid), 0, &thread_id); reinterpret_cast<LPVOID>(static_cast<uintptr_t>(pid)), 0, &thread_id);
EXPECT_NE(static_cast<HANDLE>(NULL), thread); EXPECT_NE(static_cast<HANDLE>(NULL), thread);
EXPECT_EQ(WAIT_OBJECT_0, WaitForSingleObject(thread, INFINITE)); EXPECT_EQ(WAIT_OBJECT_0, WaitForSingleObject(thread, INFINITE));
EXPECT_EQ(WAIT_OBJECT_0, WaitForSingleObject(event, INFINITE)); EXPECT_EQ(WAIT_OBJECT_0, WaitForSingleObject(event, INFINITE));
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment