diff options
author | pcc <pcc@chromium.org> | 2015-08-17 10:51:33 -0700 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2015-08-17 17:52:15 +0000 |
commit | 1c4263729030f149a30813b97b90dcac22fd21fe (patch) | |
tree | f4a61fa18e12192258fca90836f12d0d098a60b6 /content/child/geofencing | |
parent | 5225f598076767dbe20e8dd6db3fae37780be0e4 (diff) | |
download | chromium_src-1c4263729030f149a30813b97b90dcac22fd21fe.zip chromium_src-1c4263729030f149a30813b97b90dcac22fd21fe.tar.gz chromium_src-1c4263729030f149a30813b97b90dcac22fd21fe.tar.bz2 |
content: Fix bad casts from thread-local pointers.
The classes GeofencingDispatcher, ServiceWorkerDispatcher and
BluetoothDispatcher all follow a similar pattern of maintaining a
thread-local pointer that is set to integer 1 for deleted objects. This
is incompatible with Clang's bad cast checker, which assumes that
non-zero object pointers to objects of dynamic type are valid. Fix
this by maintaining the thread-local pointer as a void*, and casting
to the relevant type only if the pointer is valid.
BUG=507755
R=kinuko@chromium.org
Review URL: https://codereview.chromium.org/1284983003
Cr-Commit-Position: refs/heads/master@{#343710}
Diffstat (limited to 'content/child/geofencing')
-rw-r--r-- | content/child/geofencing/geofencing_dispatcher.cc | 14 |
1 files changed, 7 insertions, 7 deletions
diff --git a/content/child/geofencing/geofencing_dispatcher.cc b/content/child/geofencing/geofencing_dispatcher.cc index 2dda752..e067008 100644 --- a/content/child/geofencing/geofencing_dispatcher.cc +++ b/content/child/geofencing/geofencing_dispatcher.cc @@ -22,11 +22,10 @@ namespace content { namespace { -base::LazyInstance<base::ThreadLocalPointer<GeofencingDispatcher>>::Leaky - g_dispatcher_tls = LAZY_INSTANCE_INITIALIZER; +base::LazyInstance<base::ThreadLocalPointer<void>>::Leaky g_dispatcher_tls = + LAZY_INSTANCE_INITIALIZER; -GeofencingDispatcher* const kHasBeenDeleted = - reinterpret_cast<GeofencingDispatcher*>(0x1); +void* const kHasBeenDeleted = reinterpret_cast<void*>(0x1); int CurrentWorkerId() { return WorkerTaskRunner::Instance()->CurrentWorkerId(); @@ -36,7 +35,7 @@ int CurrentWorkerId() { GeofencingDispatcher::GeofencingDispatcher(ThreadSafeSender* sender) : thread_safe_sender_(sender) { - g_dispatcher_tls.Pointer()->Set(this); + g_dispatcher_tls.Pointer()->Set(static_cast<void*>(this)); } GeofencingDispatcher::~GeofencingDispatcher() { @@ -141,7 +140,8 @@ GeofencingDispatcher* GeofencingDispatcher::GetOrCreateThreadSpecificInstance( g_dispatcher_tls.Pointer()->Set(NULL); } if (g_dispatcher_tls.Pointer()->Get()) - return g_dispatcher_tls.Pointer()->Get(); + return static_cast<GeofencingDispatcher*>( + g_dispatcher_tls.Pointer()->Get()); GeofencingDispatcher* dispatcher = new GeofencingDispatcher(thread_safe_sender); @@ -153,7 +153,7 @@ GeofencingDispatcher* GeofencingDispatcher::GetOrCreateThreadSpecificInstance( GeofencingDispatcher* GeofencingDispatcher::GetThreadSpecificInstance() { if (g_dispatcher_tls.Pointer()->Get() == kHasBeenDeleted) return NULL; - return g_dispatcher_tls.Pointer()->Get(); + return static_cast<GeofencingDispatcher*>(g_dispatcher_tls.Pointer()->Get()); } void GeofencingDispatcher::OnRegisterRegionComplete(int thread_id, |