From 75034a8ad5727b511a8925c2bafad27312fdae34 Mon Sep 17 00:00:00 2001
From: Vakho Tsulaia <tsulaia@cern.ch>
Date: Thu, 23 Jan 2025 12:19:42 -0800
Subject: [PATCH] GeoPcon+GeoPgon: added some basic sanity checks

---
 GeoModelCore/GeoModelKernel/src/GeoPcon.cxx | 13 +++++++++++++
 GeoModelCore/GeoModelKernel/src/GeoPgon.cxx | 13 +++++++++++++
 2 files changed, 26 insertions(+)

diff --git a/GeoModelCore/GeoModelKernel/src/GeoPcon.cxx b/GeoModelCore/GeoModelKernel/src/GeoPcon.cxx
index f294264bc..e3aa845da 100755
--- a/GeoModelCore/GeoModelKernel/src/GeoPcon.cxx
+++ b/GeoModelCore/GeoModelKernel/src/GeoPcon.cxx
@@ -93,6 +93,16 @@ bool GeoPcon::contains (double x, double y, double z) const
 
 void GeoPcon::addPlane (double ZPlane, double RMinPlane, double RMaxPlane)
 {
+  // Basic sanity checks
+  if(RMinPlane < 0.
+     || RMaxPlane <= 0.
+     || RMaxPlane < RMinPlane) {
+    THROW_EXCEPTION("GeoPcon::addPlane() wrong arguments! ("
+		    << ZPlane << ","
+		    << RMinPlane << ","
+		    << RMaxPlane << ")");
+  }
+
   m_zPlane.push_back (ZPlane);
   m_rMinPlane.push_back (RMinPlane);
   m_rMaxPlane.push_back (RMaxPlane);
@@ -100,5 +110,8 @@ void GeoPcon::addPlane (double ZPlane, double RMinPlane, double RMaxPlane)
 
 void GeoPcon::exec (GeoShapeAction *action) const
 {
+  if (!isValid ())
+    THROW_EXCEPTION("Requested to execute action for incomplete polycone");
+
   action->handlePcon(this);
 }
diff --git a/GeoModelCore/GeoModelKernel/src/GeoPgon.cxx b/GeoModelCore/GeoModelKernel/src/GeoPgon.cxx
index 1a55a617e..ed7ccd827 100755
--- a/GeoModelCore/GeoModelKernel/src/GeoPgon.cxx
+++ b/GeoModelCore/GeoModelKernel/src/GeoPgon.cxx
@@ -148,6 +148,16 @@ bool GeoPgon::contains (double x, double y, double z) const
 
 void GeoPgon::addPlane (double ZPlane, double RMinPlane, double RMaxPlane)
 {
+  // Basic sanity checks
+  if(RMinPlane < 0.
+     || RMaxPlane <= 0.
+     || RMaxPlane < RMinPlane) {
+    THROW_EXCEPTION("GeoPcon::addPlane() wrong arguments! ("
+		    << ZPlane << ","
+		    << RMinPlane << ","
+		    << RMaxPlane << ")");
+  }
+
   m_zPlane.push_back (ZPlane);
   m_rMinPlane.push_back (RMinPlane);
   m_rMaxPlane.push_back (RMaxPlane);
@@ -155,5 +165,8 @@ void GeoPgon::addPlane (double ZPlane, double RMinPlane, double RMaxPlane)
 
 void GeoPgon::exec (GeoShapeAction *action) const
 {
+  if (!isValid ())
+    THROW_EXCEPTION("Requested to execute action for incomplete polygon");
+
   action->handlePgon(this);
 }
-- 
GitLab