From 86c9866d34cde9e9678fecd2bdb3bba4e8c2f38b Mon Sep 17 00:00:00 2001 From: mpv Date: Thu, 18 Aug 2016 14:17:41 +0300 Subject: [PATCH] Avoid of reference to not-initialized attributes values --- src/GeomValidators/GeomValidators_ZeroOffset.cpp | 12 ++++++------ src/PartSet/PartSet_WidgetPoint2d.cpp | 9 ++++----- 2 files changed, 10 insertions(+), 11 deletions(-) diff --git a/src/GeomValidators/GeomValidators_ZeroOffset.cpp b/src/GeomValidators/GeomValidators_ZeroOffset.cpp index 20d324edd..e66cc4333 100644 --- a/src/GeomValidators/GeomValidators_ZeroOffset.cpp +++ b/src/GeomValidators/GeomValidators_ZeroOffset.cpp @@ -87,11 +87,11 @@ bool GeomValidators_ZeroOffset::isValid(const std::shared_ptr& double aToSize = 0.0; double aFromSize = 0.0; - if(theFeature->real(*anIt)) { + if(theFeature->real(*anIt) && theFeature->real(*anIt)->isInitialized()) { aToSize = theFeature->real(*anIt)->value(); } anIt++; - if(theFeature->real(*anIt)) { + if(theFeature->real(*anIt) && theFeature->real(*anIt)->isInitialized()) { aFromSize = theFeature->real(*anIt)->value(); } anIt++; @@ -109,7 +109,7 @@ bool GeomValidators_ZeroOffset::isValid(const std::shared_ptr& std::shared_ptr aFromShape; std::shared_ptr anAttrSel = theFeature->selection(*anIt); - if(anAttrSel) { + if(anAttrSel && anAttrSel->isInitialized()) { aToShape = std::dynamic_pointer_cast(anAttrSel->value()); if(aToShape.get() == NULL && anAttrSel->context().get() != NULL) { aToShape = anAttrSel->context()->shape(); @@ -118,13 +118,13 @@ bool GeomValidators_ZeroOffset::isValid(const std::shared_ptr& anIt++; std::shared_ptr anAttrDouble = theFeature->real(*anIt); - if(anAttrDouble) { + if(anAttrDouble && anAttrDouble->isInitialized()) { aToSize = anAttrDouble->value(); } anIt++; anAttrSel = theFeature->selection(*anIt); - if(anAttrSel) { + if(anAttrSel && anAttrSel->isInitialized()) { aFromShape = std::dynamic_pointer_cast(anAttrSel->value()); if(aFromShape.get() == NULL && anAttrSel->context().get() != NULL) { aFromShape = anAttrSel->context()->shape(); @@ -133,7 +133,7 @@ bool GeomValidators_ZeroOffset::isValid(const std::shared_ptr& anIt++; anAttrDouble = theFeature->real(*anIt); - if(anAttrDouble) { + if(anAttrDouble && anAttrDouble->isInitialized()) { aFromSize = anAttrDouble->value(); } diff --git a/src/PartSet/PartSet_WidgetPoint2d.cpp b/src/PartSet/PartSet_WidgetPoint2d.cpp index a36b0a0c1..6bdd0009b 100644 --- a/src/PartSet/PartSet_WidgetPoint2d.cpp +++ b/src/PartSet/PartSet_WidgetPoint2d.cpp @@ -137,11 +137,6 @@ bool PartSet_WidgetPoint2D::isValidSelectionCustom(const ModuleBase_ViewerPrsPtr /// the selection is not possible if the current feature has no presentation for the current /// attribute not in AIS not in results. If so, no object in current feature where make /// coincidence, so selection is not necessary - std::shared_ptr aData = myFeature->data(); - std::shared_ptr aPointAttr = std::dynamic_pointer_cast( - aData->attribute(attributeID())); - std::shared_ptr aPoint = aPointAttr->pnt(); - bool aFoundPoint = false; GeomShapePtr anAISShape; GeomPresentablePtr aPrs = std::dynamic_pointer_cast(myFeature); @@ -157,6 +152,10 @@ bool PartSet_WidgetPoint2D::isValidSelectionCustom(const ModuleBase_ViewerPrsPtr return true; /// analysis of AIS + std::shared_ptr aData = myFeature->data(); + std::shared_ptr aPointAttr = std::dynamic_pointer_cast( + aData->attribute(attributeID())); + std::shared_ptr aPoint = aPointAttr->pnt(); if (anAISShape.get()) aFoundPoint = shapeContainsPoint(anAISShape, aPoint, mySketch); -- 2.39.2