PVS: V522 There might be dereferencing of a potential null pointer

This commit is contained in:
wmayer
2020-07-17 11:01:14 +02:00
parent 39fe47b9de
commit e9bc970c28
15 changed files with 78 additions and 87 deletions

View File

@@ -2087,14 +2087,16 @@ int FemMesh::addGroup(const std::string TypeString, const std::string Name, cons
return aId;
}
void FemMesh::addGroupElements(const int GroupId, const std::set<int> ElementIds)
void FemMesh::addGroupElements(int GroupId, const std::set<int>& ElementIds)
{
SMESH_Group* group = this->getSMesh()->GetGroup(GroupId);
if (!group) {
throw std::runtime_error("AddGroupElements: No group for given id.");
}
SMESHDS_Group* groupDS = dynamic_cast<SMESHDS_Group*>(group->GetGroupDS());
// TODO: is this dynamic_cast OK?
if (!groupDS) {
throw std::runtime_error("addGroupElements: Failed to add group elements.");
}
// Traverse the full mesh and add elements to group if id is in set 'ids'
// and if group type is compatible with element

View File

@@ -137,7 +137,7 @@ public:
/// Adds group to mesh
int addGroup(const std::string, const std::string, const int=-1);
/// Adds elements to group (int due to int used by raw SMESH functions)
void addGroupElements(int, std::set<int>);
void addGroupElements(int, const std::set<int>&);
/// Remove group (Name due to similarity to SMESH basis functions)
bool removeGroup(int);
//@}

View File

@@ -392,7 +392,9 @@ void ViewProviderFemMesh::onChanged(const App::Property* prop)
else if (prop == &ShowInner ) {
// recalc mesh with new settings
ViewProviderFEMMeshBuilder builder;
builder.createMesh(&(dynamic_cast<Fem::FemMeshObject*>(this->pcObject)->FemMesh), pcCoords, pcFaces, pcLines, vFaceElementIdx, vNodeElementIdx, onlyEdges, ShowInner.getValue(), MaxFacesShowInner.getValue());
builder.createMesh(&(static_cast<Fem::FemMeshObject*>(this->pcObject)->FemMesh),
pcCoords, pcFaces, pcLines, vFaceElementIdx, vNodeElementIdx,
onlyEdges, ShowInner.getValue(), MaxFacesShowInner.getValue());
}
else if (prop == &LineWidth) {
pcDrawStyle->lineWidth = LineWidth.getValue();

View File

@@ -100,8 +100,8 @@ void DrawWeldSymbol::onSettingDocument()
DrawTileWeld* tile2 = dynamic_cast<DrawTileWeld*>(tile2Obj);
if (tile2 != nullptr) {
tile2->TileParent.setValue(this);
tile2->TileRow.setValue(-1); //other side is row -1
}
tile2->TileRow.setValue(-1); //other side is row -1
DrawView::onSettingDocument();
}

View File

@@ -401,10 +401,9 @@ bool ShapeExtractor::isDraftPoint(App::DocumentObject* obj)
// Base::Console().Message("SE::isDraftPoint()\n");
bool result = false;
//if the docObj doesn't have a Proxy property, it definitely isn't a Draft point
App::Property* proxy = obj->getPropertyByName("Proxy");
App::PropertyPythonObject* proxy = dynamic_cast<App::PropertyPythonObject*>(obj->getPropertyByName("Proxy"));
if (proxy != nullptr) {
App::PropertyPythonObject* proxyPy = dynamic_cast<App::PropertyPythonObject*>(proxy);
std::string pp = proxyPy->toString();
std::string pp = proxy->toString();
// Base::Console().Message("SE::isDraftPoint - pp: %s\n", pp.c_str());
if (pp.find("Point") != std::string::npos) {
result = true;

View File

@@ -1206,7 +1206,7 @@ void CmdTechDrawShowAll::activated(int iMsg)
Gui::ViewProvider* vp = QGIView::getViewProvider(baseFeat);
auto partVP = dynamic_cast<ViewProviderViewPart*>(vp);
if ( vp != nullptr ) {
if ( partVP != nullptr ) {
bool state = partVP->ShowAllEdges.getValue();
state = !state;
partVP->ShowAllEdges.setValue(state);

View File

@@ -1380,7 +1380,7 @@ void CmdTechDrawLandmarkDimension::activated(int iMsg)
return;
}
TechDraw::DrawViewPart* dvp = dynamic_cast<TechDraw::DrawViewPart*>(views.front());
TechDraw::DrawViewPart* dvp = static_cast<TechDraw::DrawViewPart*>(views.front());
std::vector<App::DocumentObject*> refs2d;

View File

@@ -149,36 +149,30 @@ TechDraw::DrawPage* DrawGuiUtil::findPage(Gui::Command* cmd)
bool DrawGuiUtil::isDraftObject(App::DocumentObject* obj)
{
bool result = false;
App::Property* proxy = obj->getPropertyByName("Proxy");
App::PropertyPythonObject* proxy = dynamic_cast<App::PropertyPythonObject*>(obj->getPropertyByName("Proxy"));
if (proxy != nullptr) {
//if no proxy, can not be Draft obj
//if has proxy, might be Draft obj
App::PropertyPythonObject* proxyPy = dynamic_cast<App::PropertyPythonObject*>(proxy);
std::stringstream ss;
if (proxyPy != nullptr) {
Py::Object proxyObj = proxyPy->getValue();
std::stringstream ss;
if (proxyPy != nullptr) {
Base::PyGILStateLocker lock;
try {
if (proxyObj.hasAttr("__module__")) {
Py::String mod(proxyObj.getAttr("__module__"));
ss << (std::string)mod;
if (ss.str().find("Draft") != std::string::npos) {
result = true;
} else if (ss.str().find("draft") != std::string::npos) {
result = true;
}
}
}
catch (Py::Exception&) {
Base::PyException e; // extract the Python error text
e.ReportException();
result = false;
Py::Object proxyObj = proxy->getValue();
Base::PyGILStateLocker lock;
try {
if (proxyObj.hasAttr("__module__")) {
Py::String mod(proxyObj.getAttr("__module__"));
ss << (std::string)mod;
if (ss.str().find("Draft") != std::string::npos) {
result = true;
} else if (ss.str().find("draft") != std::string::npos) {
result = true;
}
}
}
catch (Py::Exception&) {
Base::PyException e; // extract the Python error text
e.ReportException();
result = false;
}
}
return result;
}
@@ -186,31 +180,28 @@ bool DrawGuiUtil::isDraftObject(App::DocumentObject* obj)
bool DrawGuiUtil::isArchObject(App::DocumentObject* obj)
{
bool result = false;
App::Property* proxy = obj->getPropertyByName("Proxy");
App::PropertyPythonObject* proxy = dynamic_cast<App::PropertyPythonObject*>(obj->getPropertyByName("Proxy"));
if (proxy != nullptr) {
//if no proxy, can not be Arch obj
//if has proxy, might be Arch obj
App::PropertyPythonObject* proxyPy = dynamic_cast<App::PropertyPythonObject*>(proxy);
Py::Object proxyObj = proxyPy->getValue();
Py::Object proxyObj = proxy->getValue();
std::stringstream ss;
if (proxyPy != nullptr) {
Base::PyGILStateLocker lock;
try {
if (proxyObj.hasAttr("__module__")) {
Py::String mod(proxyObj.getAttr("__module__"));
ss << (std::string)mod;
//does this have to be an ArchSection, or can it be any Arch object?
if (ss.str().find("Arch") != std::string::npos) {
result = true;
}
Base::PyGILStateLocker lock;
try {
if (proxyObj.hasAttr("__module__")) {
Py::String mod(proxyObj.getAttr("__module__"));
ss << (std::string)mod;
//does this have to be an ArchSection, or can it be any Arch object?
if (ss.str().find("Arch") != std::string::npos) {
result = true;
}
}
catch (Py::Exception&) {
Base::PyException e; // extract the Python error text
e.ReportException();
result = false;
}
}
catch (Py::Exception&) {
Base::PyException e; // extract the Python error text
e.ReportException();
result = false;
}
}
return result;
@@ -218,32 +209,29 @@ bool DrawGuiUtil::isArchObject(App::DocumentObject* obj)
bool DrawGuiUtil::isArchSection(App::DocumentObject* obj)
{
bool result = false;
App::Property* proxy = obj->getPropertyByName("Proxy");
bool result = false;
App::PropertyPythonObject* proxy = dynamic_cast<App::PropertyPythonObject*>(obj->getPropertyByName("Proxy"));
if (proxy != nullptr) {
//if no proxy, can not be Arch obj
//if has proxy, might be Arch obj
App::PropertyPythonObject* proxyPy = dynamic_cast<App::PropertyPythonObject*>(proxy);
Py::Object proxyObj = proxyPy->getValue();
Py::Object proxyObj = proxy->getValue();
std::stringstream ss;
if (proxyPy != nullptr) {
Base::PyGILStateLocker lock;
try {
if (proxyObj.hasAttr("__module__")) {
Py::String mod(proxyObj.getAttr("__module__"));
ss << (std::string)mod;
//does this have to be an ArchSection, or can it be other Arch objects?
if (ss.str().find("ArchSectionPlane") != std::string::npos) {
result = true;
}
Base::PyGILStateLocker lock;
try {
if (proxyObj.hasAttr("__module__")) {
Py::String mod(proxyObj.getAttr("__module__"));
ss << (std::string)mod;
//does this have to be an ArchSection, or can it be other Arch objects?
if (ss.str().find("ArchSectionPlane") != std::string::npos) {
result = true;
}
}
catch (Py::Exception&) {
Base::PyException e; // extract the Python error text
e.ReportException();
result = false;
}
}
catch (Py::Exception&) {
Base::PyException e; // extract the Python error text
e.ReportException();
result = false;
}
}
return result;

View File

@@ -149,10 +149,10 @@ double Grabber3d::copyActiveViewToSvgFile(App::Document* appDoc,
double sourceHeight = 0.0;
double sourceAngle = 45.0;
if (sourceCam->getTypeId() == SoOrthographicCamera::getClassTypeId()) {
oCam = dynamic_cast<SoOrthographicCamera*>(sourceCam);
oCam = static_cast<SoOrthographicCamera*>(sourceCam);
sourceHeight = oCam->height.getValue();
} else if (sourceCam->getTypeId() == SoPerspectiveCamera::getClassTypeId()) {
pCam = dynamic_cast<SoPerspectiveCamera*>(sourceCam);
pCam = static_cast<SoPerspectiveCamera*>(sourceCam);
sourceAngle = pCam->heightAngle.getValue();
}
oCam = nullptr;
@@ -197,11 +197,11 @@ double Grabber3d::copyActiveViewToSvgFile(App::Document* appDoc,
svgCam->focalDistance.setValue(sourceFocal);
svgCam->aspectRatio.setValue(sourceAspect);
if (svgCam->getTypeId() == SoOrthographicCamera::getClassTypeId()) {
SoOrthographicCamera* oSvgCam = dynamic_cast<SoOrthographicCamera*>(svgCam);
SoOrthographicCamera* oSvgCam = static_cast<SoOrthographicCamera*>(svgCam);
double newHeight = sourceHeight * zoomFactor;
oSvgCam->height.setValue(newHeight);
} else if (svgCam->getTypeId() == SoPerspectiveCamera::getClassTypeId()) {
SoPerspectiveCamera* vSvgCam = dynamic_cast<SoPerspectiveCamera*>(svgCam);
SoPerspectiveCamera* vSvgCam = static_cast<SoPerspectiveCamera*>(svgCam);
vSvgCam->heightAngle.setValue(sourceAngle);
}

View File

@@ -368,7 +368,8 @@ void QGIViewBalloon::setViewPartFeature(TechDraw::DrawViewBalloon *balloon)
App::DocumentObject* docObj = balloon->SourceView.getValue();
if (docObj == nullptr) {
balloonParent = dynamic_cast<DrawView*>(docObj);
scale = balloonParent->getScale();
if (balloonParent)
scale = balloonParent->getScale();
}
float x = Rez::guiX(balloon->X.getValue() * scale) ;
@@ -509,12 +510,9 @@ void QGIViewBalloon::placeBalloon(QPointF pos)
return;
}
DrawView* balloonParent = nullptr;
App::DocumentObject* docObj = balloon->SourceView.getValue();
if (docObj == nullptr) {
DrawView* balloonParent = dynamic_cast<DrawView*>(balloon->SourceView.getValue());
if (balloonParent == nullptr) {
return;
} else {
balloonParent = dynamic_cast<DrawView*>(docObj);
}
auto featPage = balloonParent->findParentPage();

View File

@@ -858,7 +858,7 @@ void QGVPage::saveSvg(QString filename)
m_vpPage->setFrameState(saveState);
m_vpPage->setTemplateMarkers(saveState);
setExporting(false);
if (templateVisible) {
if (templateVisible && svgTemplate) {
svgTemplate->show();
}

View File

@@ -426,7 +426,7 @@ double TaskCenterLine::getCenterWidth()
delete lg;
Gui::ViewProvider* vp = QGIView::getViewProvider(m_partFeat);
auto partVP = dynamic_cast<ViewProviderViewPart*>(vp);
if ( vp != nullptr ) {
if ( partVP != nullptr ) {
width = partVP->IsoWidth.getValue();
}
return width;

View File

@@ -143,7 +143,7 @@ void TaskLineDecor::getDefaults(void)
} else {
Gui::ViewProvider* vp = QGIView::getViewProvider(m_partFeat);
auto partVP = dynamic_cast<ViewProviderViewPart*>(vp);
if ( vp != nullptr ) {
if ( partVP != nullptr ) {
m_weight = partVP->LineWidth.getValue();
m_style = Qt::SolidLine; // = 1
m_color = LineFormat::getDefEdgeColor();

View File

@@ -463,7 +463,7 @@ QPointF TaskRichAnno::calcTextStartPos(double scale)
std::vector<Base::Vector3d> points;
if (m_baseFeat != nullptr) {
if (m_baseFeat->isDerivedFrom(TechDraw::DrawLeaderLine::getClassTypeId())) {
TechDraw::DrawLeaderLine* dll = dynamic_cast<TechDraw::DrawLeaderLine*>(m_baseFeat);
TechDraw::DrawLeaderLine* dll = static_cast<TechDraw::DrawLeaderLine*>(m_baseFeat);
points = dll->WayPoints.getValues();
} else {
// Base::Console().Message("TRA::calcTextPos - m_baseFeat is not Leader\n");

View File

@@ -449,10 +449,12 @@ void ViewProviderPage::setTemplateMarkers(bool state)
Gui::Document* guiDoc = Gui::Application::Instance->getDocument(templateFeat->getDocument());
Gui::ViewProvider* vp = guiDoc->getViewProvider(templateFeat);
ViewProviderTemplate* vpt = dynamic_cast<ViewProviderTemplate*>(vp);
vpt->setMarkers(state);
QGITemplate* t = vpt->getQTemplate();
if (t != nullptr) {
t->updateView(true);
if (vpt) {
vpt->setMarkers(state);
QGITemplate* t = vpt->getQTemplate();
if (t != nullptr) {
t->updateView(true);
}
}
}