Coverity: Dereference after null check

This commit is contained in:
wmayer
2020-07-19 15:44:52 +02:00
parent 433ec2d6e4
commit 421f6c52cb
11 changed files with 59 additions and 38 deletions

View File

@@ -1463,31 +1463,36 @@ std::string ObjectIdentifier::String::toString(bool toPython) const
void ObjectIdentifier::String::checkImport(const App::DocumentObject *owner,
const App::DocumentObject *obj, String *objName)
{
if(owner && owner->getDocument() &&
str.size() &&
ExpressionParser::ExpressionImporter::reader())
{
if(owner && owner->getDocument() && str.size() &&
ExpressionParser::ExpressionImporter::reader()) {
auto reader = ExpressionParser::ExpressionImporter::reader();
if(obj || objName) {
if (obj || objName) {
bool restoreLabel = false;
str = PropertyLinkBase::importSubName(*reader,str.c_str(),restoreLabel);
if(restoreLabel) {
if(!obj) {
if (restoreLabel) {
if (!obj) {
std::bitset<32> flags;
obj = getDocumentObject(owner->getDocument(),*objName,flags);
if(!obj)
if (!obj) {
FC_ERR("Cannot find object " << objName->toString());
}
}
if (obj) {
PropertyLinkBase::restoreLabelReference(obj,str);
}
PropertyLinkBase::restoreLabelReference(obj,str);
}
} else if (str.back()!='@')
}
else if (str.back()!='@') {
str = reader->getName(str.c_str());
else{
}
else {
str.resize(str.size()-1);
auto mapped = reader->getName(str.c_str());
auto obj = owner->getDocument()->getObject(mapped);
if(!obj)
if (!obj) {
FC_ERR("Cannot find object " << str);
}
else {
isString = true;
forceIdentifier = false;

View File

@@ -613,7 +613,7 @@ void PropertyLinkList::setSize(int newSize)
{
for(int i=newSize;i<(int)_lValueList.size();++i) {
auto obj = _lValueList[i];
if(!obj && !obj->getNameInDocument())
if (!obj || !obj->getNameInDocument())
continue;
_nameMap.erase(obj->getNameInDocument());
#ifndef USE_OLD_DAG

View File

@@ -576,13 +576,14 @@ App::DocumentObject* FemVTKTools::readResult(const char* filename, App::Document
vtkSmartPointer<vtkDataSet> dataset = ds;
App::DocumentObject* result = NULL;
if(!res)
result = res;
else
if (res)
{
Base::Console().Message("FemResultObject pointer is NULL, trying to get the active object\n");
if(obj->getTypeId() == Base::Type::fromName("Fem::FemResultObjectPython"))
{
result = obj;
}
else
{
Base::Console().Message("the active object is not the correct type, do nothing\n");
@@ -594,11 +595,17 @@ App::DocumentObject* FemVTKTools::readResult(const char* filename, App::Document
std::unique_ptr<FemMesh> fmesh(new FemMesh());
importVTKMesh(dataset, fmesh.get());
static_cast<PropertyFemMesh*>(mesh->getPropertyByName("FemMesh"))->setValuePtr(fmesh.release());
static_cast<App::PropertyLink*>(result->getPropertyByName("Mesh"))->setValue(mesh);
// PropertyLink is the property type to store DocumentObject pointer
//vtkSmartPointer<vtkPointData> pd = dataset->GetPointData();
importFreeCADResult(dataset, result);
if (result)
{
// PropertyLink is the property type to store DocumentObject pointer
App::PropertyLink* link = dynamic_cast<App::PropertyLink*>(result->getPropertyByName("Mesh"));
if (link)
link->setValue(mesh);
//vtkSmartPointer<vtkPointData> pd = dataset->GetPointData();
importFreeCADResult(dataset, result);
}
pcDoc->recompute();
Base::Console().Log(" %f: Done \n", Base::TimeInfo::diffTimeF(Start, Base::TimeInfo()));
@@ -866,6 +873,7 @@ void FemVTKTools::exportFreeCADResult(const App::DocumentObject* result, vtkSmar
field = static_cast<App::PropertyFloatList*>(res->getPropertyByName(it->first.c_str()));
else
Base::Console().Error("PropertyFloatList %s not found \n", it->first.c_str());
if (field && field->getSize() > 0) {
//if (nPoints != field->getSize())
// Base::Console().Error("Size of PropertyFloatList = %d, not equal to vtk mesh node count %d \n", field->getSize(), nPoints);
@@ -890,9 +898,10 @@ void FemVTKTools::exportFreeCADResult(const App::DocumentObject* result, vtkSmar
grid->GetPointData()->AddArray(data);
Base::Console().Log(" The PropertyFloatList %s was exported to VTK scalar list: %s\n", it->first.c_str(), it->second.c_str());
}
else
}
else if (field) {
Base::Console().Log(" PropertyFloatList NOT exported to vtk: %s size is: %i\n", it->first.c_str(), field->getSize());
}
}
Base::Console().Log("End: Create VTK result data from FreeCAD result data.\n");

View File

@@ -1129,7 +1129,8 @@ TDF_Label ExportOCAF2::exportObject(App::DocumentObject* parentObj,
App::DocumentObject *obj;
auto shape = Part::Feature::getTopoShape(parentObj,sub,false,0,&obj,false,!sub);
if(!obj || shape.isNull()) {
FC_WARN(obj->getFullName() << " has null shape");
if (obj)
FC_WARN(obj->getFullName() << " has null shape");
return TDF_Label();
}

View File

@@ -2210,16 +2210,18 @@ private:
if (!PyArg_ParseTuple(args.ptr(), "sss",&sub,&mapped,&element))
throw Py::Exception();
std::string subname(sub);
if(subname.size() && subname[subname.size()-1]!='.')
if (subname.size() && subname[subname.size()-1]!='.')
subname += '.';
if(mapped && mapped[0]) {
if(!Data::ComplexGeoData::isMappedElement(mapped))
if (mapped && mapped[0]) {
if (!Data::ComplexGeoData::isMappedElement(mapped))
subname += Data::ComplexGeoData::elementMapPrefix();
subname += mapped;
if(element && element[0] && subname[subname.size()-1]!='.')
subname += '.';
}
subname += element;
if (element && element[0]) {
if (subname.size() && subname[subname.size()-1]!='.')
subname += '.';
subname += element;
}
return Py::String(subname);
}
};

View File

@@ -929,11 +929,10 @@ void ViewProviderPartExt::reload()
void ViewProviderPartExt::updateData(const App::Property* prop)
{
const char *propName = prop?prop->getName():"";
if(propName && (strcmp(propName,"Shape")==0 || strstr(propName,"Touched")!=0))
{
const char *propName = prop->getName();
if (propName && (strcmp(propName, "Shape") == 0 || strstr(propName, "Touched") != nullptr)) {
// calculate the visual only if visible
if (isUpdateForced()||Visibility.getValue())
if (isUpdateForced() || Visibility.getValue())
updateVisual();
else
VisualTouched = true;

View File

@@ -407,7 +407,7 @@ void SheetView::currentChanged ( const QModelIndex & current, const QModelIndex
void SheetView::updateCell(const App::Property *prop)
{
try {
if (sheet && prop == &sheet->Label) {
if (prop == &sheet->Label) {
QString cap = QString::fromUtf8(sheet->Label.getValue());
setWindowTitle(cap);
}

View File

@@ -366,7 +366,7 @@ void QGIViewBalloon::setViewPartFeature(TechDraw::DrawViewBalloon *balloon)
DrawView* balloonParent = nullptr;
double scale = 1.0;
App::DocumentObject* docObj = balloon->SourceView.getValue();
if (docObj == nullptr) {
if (docObj) {
balloonParent = dynamic_cast<DrawView*>(docObj);
if (balloonParent)
scale = balloonParent->getScale();

View File

@@ -97,8 +97,10 @@ TaskCenterLine::TaskCenterLine(TechDraw::DrawViewPart* partFeat,
if (m_cl == nullptr) { //checked by CommandAnnotate. Should never happen.
Base::Console().Message("TCL::TCL() - no centerline found\n");
}
m_type = m_cl->m_type;
m_mode = m_cl->m_mode;
else {
m_type = m_cl->m_type;
m_mode = m_cl->m_mode;
}
setUiEdit();
}

View File

@@ -95,6 +95,7 @@ TaskDetail::TaskDetail(TechDraw::DrawViewPart* baseFeat):
m_basePage = m_baseFeat->findParentPage();
if (m_basePage == nullptr) {
Base::Console().Error("TaskDetail - bad parameters - base page. Can not proceed.\n");
return;
}
m_baseName = m_baseFeat->getNameInDocument();

View File

@@ -421,7 +421,9 @@ void TaskLeaderLine::createLeaderFeature(std::vector<Base::Vector3d> converted)
if (m_basePage != nullptr) {
m_basePage->touch();
}
m_lineFeat->requestPaint();
if (m_lineFeat != nullptr) {
m_lineFeat->requestPaint();
}
}
void TaskLeaderLine::updateLeaderFeature(void)