From a10492ff33152cef5a835761125219d3e4ee21d0 Mon Sep 17 00:00:00 2001 From: brucedawson Date: Tue, 6 Oct 2015 13:34:30 -0700 Subject: [PATCH] Fix VS 2015 warning by adding an additional cast The OwningThread member of CRITICAL_SECTION is declared as having type HANDLE but it is actually the thread's Thread ID which is a DWORD. When doing 64-bit builds of Chromium with VS 2015 this triggers a warning because of the suspicious conversion from 32-bit integer to 64-bit pointer. This change adds a cast (and some comments) to make the conversion explicit and avoid the warning. R=henrikg@webrtc.org BUG=440500 Review URL: https://codereview.webrtc.org/1386183002 Cr-Commit-Position: refs/heads/master@{#10190} --- webrtc/base/criticalsection.cc | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/webrtc/base/criticalsection.cc b/webrtc/base/criticalsection.cc index 851635d051..1f50c2355d 100644 --- a/webrtc/base/criticalsection.cc +++ b/webrtc/base/criticalsection.cc @@ -88,7 +88,12 @@ void CriticalSection::Leave() UNLOCK_FUNCTION() { bool CriticalSection::CurrentThreadIsOwner() const { #if defined(WEBRTC_WIN) - return crit_.OwningThread == reinterpret_cast(GetCurrentThreadId()); + // OwningThread has type HANDLE but actually contains the Thread ID: + // http://stackoverflow.com/questions/12675301/why-is-the-owningthread-member-of-critical-section-of-type-handle-when-it-is-de + // Converting through size_t avoids the VS 2015 warning C4312: conversion from + // 'type1' to 'type2' of greater size + return crit_.OwningThread == + reinterpret_cast(static_cast(GetCurrentThreadId())); #else #if CS_DEBUG_CHECKS return pthread_equal(thread_, pthread_self());