Salome HOME
Fix SIGSEGV on string representation of empty MEDCoupling1[S,D]GTUMesh
authorAnthony GEAY <anthony.geay@edf.fr>
Wed, 18 Nov 2020 06:31:14 +0000 (07:31 +0100)
committerAnthony GEAY <anthony.geay@edf.fr>
Wed, 18 Nov 2020 06:31:14 +0000 (07:31 +0100)
src/MEDCoupling/MEDCoupling1GTUMesh.cxx
src/MEDCoupling_Swig/MEDCouplingBasicsTest7.py

index 2f7a66e59ab85dfbfb0ac03c1cba30b28772e5e7..34562b01149829eae0325c3d33b02b3f1ba59097 100644 (file)
@@ -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 ; }
index d279d1b2cbcc50ae2eccc570a5b89f597f5a33a0..50157f5c60a4a93ef6a51daa9fd278ec996ded3d 100644 (file)
@@ -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__':