From d7b1216f56996b6d25ccb10c7375ae53486a974a Mon Sep 17 00:00:00 2001 From: Ray Speth Date: Thu, 28 Jan 2016 15:26:36 -0500 Subject: [PATCH] [Reactor] Fix null pointer dereference in FlowDevice::install Taking the address of a dereferenced null pointer is still undefined behavior. This was causing the test TestReactor.test_valve_errors to fail on some versions of OS X. --- include/cantera/zeroD/ReactorBase.h | 8 ++++++++ src/zeroD/FlowDevice.cpp | 4 ---- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/include/cantera/zeroD/ReactorBase.h b/include/cantera/zeroD/ReactorBase.h index 5f529b42c..856397f9b 100644 --- a/include/cantera/zeroD/ReactorBase.h +++ b/include/cantera/zeroD/ReactorBase.h @@ -133,10 +133,18 @@ public: //! return a reference to the contents. thermo_t& contents() { + if (!m_thermo) { + throw CanteraError("ReactorBase::contents", + "Reactor contents not defined."); + } return *m_thermo; } const thermo_t& contents() const { + if (!m_thermo) { + throw CanteraError("ReactorBase::contents", + "Reactor contents not defined."); + } return *m_thermo; } diff --git a/src/zeroD/FlowDevice.cpp b/src/zeroD/FlowDevice.cpp index 00c3bac63..20286637b 100644 --- a/src/zeroD/FlowDevice.cpp +++ b/src/zeroD/FlowDevice.cpp @@ -19,10 +19,6 @@ bool FlowDevice::install(ReactorBase& in, ReactorBase& out) // construct adapters between inlet and outlet species ThermoPhase* mixin = &m_in->contents(); ThermoPhase* mixout = &m_out->contents(); - if (mixin == 0 || mixout == 0) { - throw CanteraError("FlowDevice::install", "Can't install flow device " - "until reactor contents have been assigned."); - } m_nspin = mixin->nSpecies(); m_nspout = mixout->nSpecies();