From: Anthony GEAY Date: Wed, 18 Nov 2020 06:31:14 +0000 (+0100) Subject: Fix SIGSEGV on string representation of empty MEDCoupling1[S,D]GTUMesh X-Git-Tag: V9_6_asterxx_0~1 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=af8a6b836ed960509fcb2d719d7396c187dfbf2b;p=tools%2Fmedcoupling.git Fix SIGSEGV on string representation of empty MEDCoupling1[S,D]GTUMesh --- diff --git a/src/MEDCoupling/MEDCoupling1GTUMesh.cxx b/src/MEDCoupling/MEDCoupling1GTUMesh.cxx index 2f7a66e59..34562b011 100644 --- a/src/MEDCoupling/MEDCoupling1GTUMesh.cxx +++ b/src/MEDCoupling/MEDCoupling1GTUMesh.cxx @@ -781,6 +781,11 @@ std::string MEDCoupling1SGTUMesh::simpleRepr() const { static const char msg0[]="No coordinates specified !"; std::ostringstream ret; + if(!_cm) + { + ret << "No geometric type specified" << std::endl; + return ret.str(); + } ret << "Single static geometic type (" << _cm->getRepr() << ") unstructured mesh with name : \"" << getName() << "\"\n"; ret << "Description of mesh : \"" << getDescription() << "\"\n"; int tmpp1,tmpp2; @@ -1414,7 +1419,13 @@ DataArrayIdType *MEDCoupling1SGTUMesh::simplexizePlanarFace6() void MEDCoupling1SGTUMesh::reprQuickOverview(std::ostream& stream) const { - stream << "MEDCoupling1SGTUMesh C++ instance at " << this << ". Type=" << _cm->getRepr() << ". Name : \"" << getName() << "\"."; + stream << "MEDCoupling1SGTUMesh C++ instance at " << this << ". Type="; + if(!_cm) + { + stream << "Not set"; + return ; + } + stream << _cm->getRepr() << ". Name : \"" << getName() << "\"."; stream << " Mesh dimension : " << getMeshDimension() << "."; if(!_coords) { stream << " No coordinates set !"; return ; } @@ -2563,6 +2574,8 @@ mcIdType MEDCoupling1DGTUMesh::getNumberOfNodesInCell(mcIdType cellId) const std::string MEDCoupling1DGTUMesh::simpleRepr() const { static const char msg0[]="No coordinates specified !"; + if(!_cm) + return std::string("Cell type not specified"); std::ostringstream ret; ret << "Single dynamic geometic type (" << _cm->getRepr() << ") unstructured mesh with name : \"" << getName() << "\"\n"; ret << "Description of mesh : \"" << getDescription() << "\"\n"; @@ -2800,7 +2813,13 @@ DataArrayIdType *MEDCoupling1DGTUMesh::simplexize(int policy) void MEDCoupling1DGTUMesh::reprQuickOverview(std::ostream& stream) const { - stream << "MEDCoupling1DGTUMesh C++ instance at " << this << ". Type=" << _cm->getRepr() << ". Name : \"" << getName() << "\"."; + stream << "MEDCoupling1DGTUMesh C++ instance at " << this << ". Type="; + if(!_cm) + { + stream << "Not defined"; + return ; + } + stream << _cm->getRepr() << ". Name : \"" << getName() << "\"."; stream << " Mesh dimension : " << getMeshDimension() << "."; if(!_coords) { stream << " No coordinates set !"; return ; } diff --git a/src/MEDCoupling_Swig/MEDCouplingBasicsTest7.py b/src/MEDCoupling_Swig/MEDCouplingBasicsTest7.py index d279d1b2c..50157f5c6 100644 --- a/src/MEDCoupling_Swig/MEDCouplingBasicsTest7.py +++ b/src/MEDCoupling_Swig/MEDCouplingBasicsTest7.py @@ -910,6 +910,19 @@ class MEDCouplingBasicsTest7(unittest.TestCase): self.assertTrue(d.eigenValues().isEqual(valuesExp,1e-12)) pass + def testBugOnReprOf1SGTUMesh(self): + """ Non reg bug on repr of empty MEDCoupling1SGTUMesh instance """ + m = MEDCoupling1SGTUMesh() + m.simpleRepr() + str(m) + m.advancedRepr() + repr(m) + m = MEDCoupling1DGTUMesh() + m.simpleRepr() + str(m) + m.advancedRepr() + repr(m) + pass if __name__ == '__main__':