Skip to content

Commit 21870fa

Browse files
N-Dekkerdzenanz
authored andcommitted
BUG: Replace bit_cast<HANDLE> calls with reinterpret_cast<HANDLE>
It appears that commit 548b45f ("BUG: Replace C-style casts from `_beginthreadex` with `bit_cast<HANDLE>`", from pull request #3380) was wrong: `bit_cast<HANDLE>` might do a different conversion than the corresponding C-style cast, `(HANDLE)`. The C-style cast `(HANDLE)` behaves exactly like `reinterpret_cast<HANDLE>`, by definition. `reinterpret_cast<HANDLE>` does an implementation-defined conversion, as was explained by Jonathan Wakely at isocpp/CppCoreGuidelines#1517 (comment) (issue "Favor bit_cast over reinterpret_cast"). Fixed by replacing all `bit_cast<HANDLE>` calls with `reinterpret_cast<HANDLE>`.
1 parent 230839e commit 21870fa

File tree

1 file changed

+5
-6
lines changed

1 file changed

+5
-6
lines changed

Modules/Core/Common/src/itkPlatformMultiThreaderWindows.cxx

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@
2626
*
2727
*=========================================================================*/
2828
#include "itkPlatformMultiThreader.h"
29-
#include "itkBitCast.h"
3029
#include "itkObjectFactory.h"
3130
#include "itksys/SystemTools.hxx"
3231
#include <cstdlib>
@@ -72,7 +71,7 @@ PlatformMultiThreader::MultipleMethodExecute()
7271
m_ThreadInfoArray[threadCount].UserData = m_MultipleData[threadCount];
7372
m_ThreadInfoArray[threadCount].NumberOfWorkUnits = m_NumberOfWorkUnits;
7473

75-
processId[threadCount] = bit_cast<HANDLE>(_beginthreadex(
74+
processId[threadCount] = reinterpret_cast<HANDLE>(_beginthreadex(
7675
nullptr, 0, m_MultipleMethod[threadCount], &m_ThreadInfoArray[threadCount], 0, (unsigned int *)&threadId));
7776

7877
if (processId[threadCount] == nullptr)
@@ -137,8 +136,8 @@ PlatformMultiThreader::SpawnThread(ThreadFunctionType f, void * UserData)
137136

138137
// Using _beginthreadex on a PC
139138
//
140-
m_SpawnedThreadProcessID[id] =
141-
bit_cast<HANDLE>(_beginthreadex(nullptr, 0, f, &m_SpawnedThreadInfoArray[id], 0, (unsigned int *)&threadId));
139+
m_SpawnedThreadProcessID[id] = reinterpret_cast<HANDLE>(
140+
_beginthreadex(nullptr, 0, f, &m_SpawnedThreadInfoArray[id], 0, (unsigned int *)&threadId));
142141
if (m_SpawnedThreadProcessID[id] == nullptr)
143142
{
144143
itkExceptionMacro("Error in thread creation !!!");
@@ -177,8 +176,8 @@ PlatformMultiThreader::SpawnDispatchSingleMethodThread(PlatformMultiThreader::Wo
177176
{
178177
// Using _beginthreadex on a PC
179178
DWORD threadId;
180-
auto threadHandle =
181-
bit_cast<HANDLE>(_beginthreadex(nullptr, 0, this->SingleMethodProxy, threadInfo, 0, (unsigned int *)&threadId));
179+
auto threadHandle = reinterpret_cast<HANDLE>(
180+
_beginthreadex(nullptr, 0, this->SingleMethodProxy, threadInfo, 0, (unsigned int *)&threadId));
182181
if (threadHandle == nullptr)
183182
{
184183
itkExceptionMacro("Error in thread creation !!!");

0 commit comments

Comments
 (0)