Salome HOME
Avoid SIGSEGV in WhatIs and PrintShapeErrors methods when shape is NULL mbs/35366_SigSegV_WhatIs 2/head 3/head
authormbs <martin.bernhard@opencascade.com>
Tue, 16 May 2023 10:29:26 +0000 (11:29 +0100)
committermbs <martin.bernhard@opencascade.com>
Tue, 16 May 2023 10:29:26 +0000 (11:29 +0100)
src/GEOM_I/GEOM_IMeasureOperations_i.cc

index a740731b4b648c22badcb4e0f6115774649c1274..6efb24688c819a08933e22c651b18c45f9aa5b78 100644 (file)
@@ -31,6 +31,8 @@
 #include "GEOM_Engine.hxx"
 #include "GEOM_Object.hxx"
 
+#define WRN_SHAPE_IS_NULL   "WRN_SHAPE_IS_NULL"
+
 /**
  * This function converts shape errors from theErrorsFrom to theErrorsTo.
  * Note that theErrorsTo is not cleared at first.
@@ -690,8 +692,10 @@ char* GEOM_IMeasureOperations_i::PrintShapeErrors
   //Get the reference shape
   Handle(::GEOM_Object) aShape = GetObjectImpl(theShape);
 
-  if (aShape.IsNull()) {
-    return NULL;
+  if (aShape.IsNull())
+  {
+    GetOperations()->SetErrorCode(WRN_SHAPE_IS_NULL);
+    return CORBA::string_dup("");
   }
 
   // Convert the errors sequence
@@ -920,7 +924,12 @@ char* GEOM_IMeasureOperations_i::WhatIs (GEOM::GEOM_Object_ptr theShape)
 
   //Get the reference shape
   Handle(::GEOM_Object) aShape = GetObjectImpl(theShape);
-  if (aShape.IsNull()) return NULL;
+  if (aShape.IsNull())
+  {
+    //Assume the "WhatIs" operation as being done
+    GetOperations()->SetErrorCode(OK);
+    return CORBA::string_dup(WRN_SHAPE_IS_NULL);
+  }
 
   // Get shape parameters
   TCollection_AsciiString aDescription = GetOperations()->WhatIs(aShape);