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.
This commit is contained in:
Ray Speth 2013-06-24 15:21:55 +00:00
parent 123544e4f7
commit d060cba434

View file

@ -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];