diff --git a/util/mac/process_reader_test.cc b/util/mac/process_reader_test.cc index 67d90995..10a6352a 100644 --- a/util/mac/process_reader_test.cc +++ b/util/mac/process_reader_test.cc @@ -362,7 +362,7 @@ void ExpectSeveralThreads(ThreadMap* thread_map, thread.stack_region_address >= other_thread.stack_region_address && thread.stack_region_address < other_thread_stack_region_end); EXPECT_FALSE( - thread_stack_region_end > other_thread.stack_region_address & + thread_stack_region_end > other_thread.stack_region_address && thread_stack_region_end <= other_thread_stack_region_end); } } diff --git a/util/misc/initialization_state.h b/util/misc/initialization_state.h index b5a72031..b0496e5c 100644 --- a/util/misc/initialization_state.h +++ b/util/misc/initialization_state.h @@ -86,7 +86,11 @@ class InitializationState { void set_state(State state) { state_ = state; } private: - State state_; + // state_ is volatile to ensure that it’ll be set by the destructor when it + // runs. Otherwise, optimizations might prevent it from ever being set to + // kStateDestroyed, limiting this class’ ability to catch use-after-free + // errors. + volatile State state_; DISALLOW_COPY_AND_ASSIGN(InitializationState); }; diff --git a/util/misc/initialization_state_dcheck.h b/util/misc/initialization_state_dcheck.h index 11501bc7..d40aab5f 100644 --- a/util/misc/initialization_state_dcheck.h +++ b/util/misc/initialization_state_dcheck.h @@ -164,15 +164,29 @@ class InitializationStateDcheck : public InitializationState { // objects of the DCHECK_IS_ON InitializationStateDcheck class above. typedef bool InitializationStateDcheck[0]; +namespace internal { + +// This function exists to make use of the InitializationStateDcheck object so +// that it appears to be used. It always returns true, so that it can be used +// as the argument to a no-op DCHECK. +inline bool EatInitializationState(const InitializationStateDcheck*) { + return true; +} + +} // namepspace internal + // The contents of these DCHECKs will never be evaluated, but they make use of // initialization_state_dcheck to avoid triggering -Wunused-private-field // warnings. #define INITIALIZATION_STATE_SET_INITIALIZING(initialization_state_dcheck) \ - DCHECK(&(initialization_state_dcheck)) + DCHECK(::crashpad::internal::EatInitializationState( \ + &(initialization_state_dcheck))) #define INITIALIZATION_STATE_SET_VALID(initialization_state_dcheck) \ - DCHECK(&(initialization_state_dcheck)) + DCHECK(::crashpad::internal::EatInitializationState( \ + &(initialization_state_dcheck))) #define INITIALIZATION_STATE_DCHECK_VALID(initialization_state_dcheck) \ - DCHECK(&(initialization_state_dcheck)) + DCHECK(::crashpad::internal::EatInitializationState( \ + &(initialization_state_dcheck))) #endif diff --git a/util/test/posix/close_multiple.cc b/util/test/posix/close_multiple.cc index 9c70e183..86e768bf 100644 --- a/util/test/posix/close_multiple.cc +++ b/util/test/posix/close_multiple.cc @@ -17,6 +17,7 @@ #include #include #include +#include #include #include #include