From d060cba4341092ce0e4e9521e86873e6f71118c9 Mon Sep 17 00:00:00 2001 From: Ray Speth Date: Mon, 24 Jun 2013 15:21:55 +0000 Subject: [PATCH] Fix a memory error in IdealGasPhase::cv_vib and cv_tr The array 'c' is only long enough to hold the thermo parameters filled in by the StatMech class, so it's necessary to make sure the type is correct first and abort if it's not, rather than calling reportParams first and corrupting the stack. --- src/thermo/IdealGasPhase.cpp | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/src/thermo/IdealGasPhase.cpp b/src/thermo/IdealGasPhase.cpp index 261743c0f..9d7519b28 100644 --- a/src/thermo/IdealGasPhase.cpp +++ b/src/thermo/IdealGasPhase.cpp @@ -103,18 +103,18 @@ doublereal IdealGasPhase::cv_tr(doublereal atomicity) const { // k is the species number int dum = 0; - int type = 0; + int type = m_spthermo->reportType(); doublereal c[12]; doublereal minTemp_; doublereal maxTemp_; doublereal refPressure_; - m_spthermo->reportParams(dum, type, c, minTemp_, maxTemp_, refPressure_); - if (type != 111) { throw CanteraError("Error in IdealGasPhase.cpp", "cv_tr only supported for StatMech!. \n\n"); } + m_spthermo->reportParams(dum, type, c, minTemp_, maxTemp_, refPressure_); + // see reportParameters for specific details return c[3]; } @@ -134,7 +134,7 @@ doublereal IdealGasPhase::cv_vib(const int k, const doublereal T) const // k is the species number int dum = 0; - int type = 0; + int type = m_spthermo->reportType(); doublereal c[12]; doublereal minTemp_; doublereal maxTemp_; @@ -142,14 +142,13 @@ doublereal IdealGasPhase::cv_vib(const int k, const doublereal T) const c[0] = temperature(); - m_spthermo->reportParams(dum, type, c, minTemp_, maxTemp_, refPressure_); - // basic sanity check if (type != 111) { throw CanteraError("Error in IdealGasPhase.cpp", "cv_vib only supported for StatMech!. \n\n"); - } + m_spthermo->reportParams(dum, type, c, minTemp_, maxTemp_, refPressure_); + // see reportParameters for specific details return c[4];