From 4a886052f2cc7c2e63f35f23e6d8b5dd7cd1bfe2 Mon Sep 17 00:00:00 2001 From: geay Date: Wed, 14 May 2014 10:29:17 +0200 Subject: [PATCH] Protect applyLin against errors in input (bug PAL1164, CEA22584) --- src/MEDCoupling/MEDCouplingMemArray.cxx | 12 ++++++++---- src/MEDCoupling_Swig/MEDCouplingBasicsTest.py | 18 ++++++++++++++++++ 2 files changed, 26 insertions(+), 4 deletions(-) diff --git a/src/MEDCoupling/MEDCouplingMemArray.cxx b/src/MEDCoupling/MEDCouplingMemArray.cxx index 86b8c8727..c54ef2cec 100644 --- a/src/MEDCoupling/MEDCouplingMemArray.cxx +++ b/src/MEDCoupling/MEDCouplingMemArray.cxx @@ -4113,14 +4113,18 @@ DataArrayDouble *DataArrayDouble::computeAbs() const * \param [in] a - the first coefficient of the function. * \param [in] b - the second coefficient of the function. * \param [in] compoId - the index of component to modify. - * \throw If \a this is not allocated. + * \throw If \a this is not allocated, or \a compoId is not in [0,\c this->getNumberOfComponents() ). */ void DataArrayDouble::applyLin(double a, double b, int compoId) { checkAllocated(); - double *ptr=getPointer()+compoId; - int nbOfComp=getNumberOfComponents(); - int nbOfTuple=getNumberOfTuples(); + double *ptr(getPointer()+compoId); + int nbOfComp(getNumberOfComponents()),nbOfTuple(getNumberOfTuples()); + if(compoId<0 || compoId>=nbOfComp) + { + std::ostringstream oss; oss << "DataArrayDouble::applyLin : The compoId requested (" << compoId << ") is not valid ! Must be in [0," << nbOfComp << ") !"; + throw INTERP_KERNEL::Exception(oss.str().c_str()); + } for(int i=0;i