Clang tidy warnings
I've started a clang-tidy
builder in !1850 (merged). Here are some interesting things:
/builds/ben.boeckel/smtk/build/../thirdparty/delaunay/Source/Discretization/ExcisePolygon.cc:53:3: warning: Forming reference to null pointer [clang-analyzer-core.NonNullParamChecker]
removeBoundedRegion(*firstEdge.first, firstEdge.second, mesh);
^
/builds/ben.boeckel/smtk/build/../thirdparty/delaunay/Source/Discretization/ExcisePolygon.cc:36:38: note: Calling default constructor for 'pair<const Delaunay::Mesh::Edge *, bool>'
std::pair<const Mesh::Edge*, bool> firstEdge;
^
/usr/bin/../lib/gcc/x86_64-redhat-linux/9/../../../../include/c++/9/bits/stl_pair.h:230:9: note: Null pointer value stored to 'firstEdge.first'
: first(), second() { }
^
/builds/ben.boeckel/smtk/build/../thirdparty/delaunay/Source/Discretization/ExcisePolygon.cc:36:38: note: Returning from default constructor for 'pair<const Delaunay::Mesh::Edge *, bool>'
std::pair<const Mesh::Edge*, bool> firstEdge;
^
/builds/ben.boeckel/smtk/build/../thirdparty/delaunay/Source/Discretization/ExcisePolygon.cc:37:24: note: Assuming the condition is false
for (unsigned i = 0; i < polygon.GetPoints().size(); ++i)
^
/builds/ben.boeckel/smtk/build/../thirdparty/delaunay/Source/Discretization/ExcisePolygon.cc:37:3: note: Loop condition is false. Execution continues on line 52
for (unsigned i = 0; i < polygon.GetPoints().size(); ++i)
^
/builds/ben.boeckel/smtk/build/../thirdparty/delaunay/Source/Discretization/ExcisePolygon.cc:53:3: note: Forming reference to null pointer
removeBoundedRegion(*firstEdge.first, firstEdge.second, mesh);
^
What should ExcisePolygon
do if given a polygone with no points? Only one point?
/builds/ben.boeckel/smtk/build/../thirdparty/delaunay/Source/Discretization/ConstrainedDelaunayMesh.cc:93:3: warning: Forming reference to null pointer [clang-analyzer-core.NonNullParamChecker]
removeBoundedRegion(*firstEdge.first, !firstEdge.second, *augmentedMesh);
^
/builds/ben.boeckel/smtk/build/../thirdparty/delaunay/Source/Discretization/ConstrainedDelaunayMesh.cc:44:7: note: Assuming 'inSitu' is true
if (inSitu)
^
/builds/ben.boeckel/smtk/build/../thirdparty/delaunay/Source/Discretization/ConstrainedDelaunayMesh.cc:44:3: note: Taking true branch
if (inSitu)
^
/builds/ben.boeckel/smtk/build/../thirdparty/delaunay/Source/Discretization/ConstrainedDelaunayMesh.cc:74:38: note: Calling default constructor for 'pair<const Delaunay::Mesh::Edge *, bool>'
std::pair<const Mesh::Edge*, bool> firstEdge;
^
/usr/bin/../lib/gcc/x86_64-redhat-linux/9/../../../../include/c++/9/bits/stl_pair.h:230:9: note: Null pointer value stored to 'firstEdge.first'
: first(), second() { }
^
/builds/ben.boeckel/smtk/build/../thirdparty/delaunay/Source/Discretization/ConstrainedDelaunayMesh.cc:74:38: note: Returning from default constructor for 'pair<const Delaunay::Mesh::Edge *, bool>'
std::pair<const Mesh::Edge*, bool> firstEdge;
^
/builds/ben.boeckel/smtk/build/../thirdparty/delaunay/Source/Discretization/ConstrainedDelaunayMesh.cc:75:24: note: Assuming the condition is false
for (unsigned i = 0; i < polygon.GetPoints().size(); ++i)
^
/builds/ben.boeckel/smtk/build/../thirdparty/delaunay/Source/Discretization/ConstrainedDelaunayMesh.cc:75:3: note: Loop condition is false. Execution continues on line 92
for (unsigned i = 0; i < polygon.GetPoints().size(); ++i)
^
/builds/ben.boeckel/smtk/build/../thirdparty/delaunay/Source/Discretization/ConstrainedDelaunayMesh.cc:93:3: note: Forming reference to null pointer
removeBoundedRegion(*firstEdge.first, !firstEdge.second, *augmentedMesh);
^
Seems to be the same thing for a different operator.
Seem to be lots of others. You can see them here: https://gitlab.kitware.com/ben.boeckel/smtk/-/jobs/4702819
cJSON seems to have an…unfortunate relationship with the strcpy
and memcpy
functions. Why does this still exist? Why are we not using nlohmann_json instead? @dcthomp
Some other interesting things:
/builds/ben.boeckel/smtk/build/../smtk/attribute/ModelEntityItemDefinition.cxx:27:3: warning: Call to virtual function during construction [clang-analyzer-optin.cplusplus.VirtualCall]
this->setAcceptsEntries(smtk::common::typeName<smtk::model::Resource>(), "", true);
^
/builds/ben.boeckel/smtk/build/../smtk/attribute/ModelEntityItemDefinition.cxx:27:3: note: This constructor of an object of type 'ModelEntityItemDefinition' has not returned when the virtual method was called
/builds/ben.boeckel/smtk/build/../smtk/attribute/ModelEntityItemDefinition.cxx:27:3: note: Call to virtual function during construction
/builds/ben.boeckel/smtk/build/../smtk/mesh/moab/BufferedCellAllocator.cxx:49:3: warning: Call to virtual function during destruction [clang-analyzer-optin.cplusplus.VirtualCall]
this->flush();
^
/builds/ben.boeckel/smtk/build/../smtk/mesh/moab/BufferedCellAllocator.cxx:49:3: note: This destructor of an object of type '~BufferedCellAllocator' has not returned when the virtual method was called
/builds/ben.boeckel/smtk/build/../smtk/mesh/moab/BufferedCellAllocator.cxx:49:3: note: Call to virtual function during destruction
/builds/ben.boeckel/smtk/build/../smtk/mesh/moab/MergeMeshVertices.cxx:204:7: warning: Value stored to 'result' is never read [clang-analyzer-deadcode.DeadStores]
result = tree.distance_search(
^
/builds/ben.boeckel/smtk/build/../smtk/mesh/moab/MergeMeshVertices.cxx:204:7: note: Value stored to 'result' is never read
Boost memory leak?
/root/misc/root/smtk-deps/include/boost/algorithm/string/detail/classification.hpp:135:25: warning: Potential memory leak [clang-analyzer-cplusplus.NewDeleteLeaks]
if(!use_fixed_storage(m_Size) && m_Storage.m_dynSet!=0)
^
/builds/ben.boeckel/smtk/build/../smtk/attribute/Attribute.cxx:234:3: note: Calling 'split<std::vector<std::__cxx11::basic_string<char>, std::allocator<std::__cxx11::basic_string<char> > >, const std::__cxx11::basic_string<char> &, boost::algorithm::detail::is_any_ofF<char>>'
boost::split(tree, path, boost::is_any_of(seps));
^
/root/misc/root/smtk-deps/include/boost/algorithm/string/split.hpp:161:17: note: Calling 'token_finder<boost::algorithm::detail::is_any_ofF<char>>'
::boost::algorithm::token_finder( Pred, eCompress ) );
^
/root/misc/root/smtk-deps/include/boost/algorithm/string/finder.hpp:219:20: note: Calling constructor for 'token_finderF<boost::algorithm::detail::is_any_ofF<char>>'
return detail::token_finderF<PredicateT>( Pred, eCompress );
^
/root/misc/root/smtk-deps/include/boost/algorithm/string/detail/finder.hpp:554:25: note: Calling copy constructor for 'is_any_ofF<char>'
m_Pred(Pred), m_eCompress(eCompress) {}
^
/root/misc/root/smtk-deps/include/boost/algorithm/string/detail/classification.hpp:114:21: note: Taking false branch
if(use_fixed_storage(m_Size))
^
/root/misc/root/smtk-deps/include/boost/algorithm/string/detail/classification.hpp:123:44: note: Memory is allocated
m_Storage.m_dynSet=new set_value_type[m_Size];
^
/root/misc/root/smtk-deps/include/boost/algorithm/string/detail/finder.hpp:554:25: note: Returning from copy constructor for 'is_any_ofF<char>'
m_Pred(Pred), m_eCompress(eCompress) {}
^
/root/misc/root/smtk-deps/include/boost/algorithm/string/finder.hpp:219:20: note: Returning from constructor for 'token_finderF<boost::algorithm::detail::is_any_ofF<char>>'
return detail::token_finderF<PredicateT>( Pred, eCompress );
^
/root/misc/root/smtk-deps/include/boost/algorithm/string/split.hpp:161:17: note: Returned allocated memory
::boost::algorithm::token_finder( Pred, eCompress ) );
^
/root/misc/root/smtk-deps/include/boost/algorithm/string/split.hpp:161:51: note: Calling '~is_any_ofF'
::boost::algorithm::token_finder( Pred, eCompress ) );
^
/root/misc/root/smtk-deps/include/boost/algorithm/string/detail/classification.hpp:135:25: note: Potential memory leak
if(!use_fixed_storage(m_Size) && m_Storage.m_dynSet!=0)
^
/root/misc/root/smtk-deps/include/boost/algorithm/string/detail/classification.hpp:139:17: warning: Potential memory leak [clang-analyzer-cplusplus.NewDeleteLeaks]
}
^
/builds/ben.boeckel/smtk/build/../smtk/attribute/Attribute.cxx:234:3: note: Calling 'split<std::vector<std::__cxx11::basic_string<char>, std::allocator<std::__cxx11::basic_string<char> > >, const std::__cxx11::basic_string<char> &, boost::algorithm::detail::is_any_ofF<char>>'
boost::split(tree, path, boost::is_any_of(seps));
^
/root/misc/root/smtk-deps/include/boost/algorithm/string/split.hpp:161:17: note: Calling 'token_finder<boost::algorithm::detail::is_any_ofF<char>>'
::boost::algorithm::token_finder( Pred, eCompress ) );
^
/root/misc/root/smtk-deps/include/boost/algorithm/string/finder.hpp:219:55: note: Calling copy constructor for 'is_any_ofF<char>'
return detail::token_finderF<PredicateT>( Pred, eCompress );
^
/root/misc/root/smtk-deps/include/boost/algorithm/string/detail/classification.hpp:114:21: note: Taking false branch
if(use_fixed_storage(m_Size))
^
/root/misc/root/smtk-deps/include/boost/algorithm/string/detail/classification.hpp:123:44: note: Memory is allocated
m_Storage.m_dynSet=new set_value_type[m_Size];
^
/root/misc/root/smtk-deps/include/boost/algorithm/string/finder.hpp:219:55: note: Returning from copy constructor for 'is_any_ofF<char>'
return detail::token_finderF<PredicateT>( Pred, eCompress );
^
/root/misc/root/smtk-deps/include/boost/algorithm/string/finder.hpp:219:55: note: Calling '~is_any_ofF'
/root/misc/root/smtk-deps/include/boost/algorithm/string/detail/classification.hpp:135:51: note: Left side of '&&' is false
if(!use_fixed_storage(m_Size) && m_Storage.m_dynSet!=0)
^
/root/misc/root/smtk-deps/include/boost/algorithm/string/detail/classification.hpp:139:17: note: Potential memory leak
}
^
Potential uninitialized read:
/builds/ben.boeckel/smtk/build/../smtk/mesh/operators/ExtractByDihedralAngle.cxx:222:7: warning: Branch condition evaluates to a garbage value [clang-analyzer-core.uninitialized.Branch]
if (shellCreated)
^
/builds/ben.boeckel/smtk/build/../smtk/mesh/operators/ExtractByDihedralAngle.cxx:153:7: note: Assuming the condition is false
if (meshset.isValid() == false)
^
/builds/ben.boeckel/smtk/build/../smtk/mesh/operators/ExtractByDihedralAngle.cxx:153:3: note: Taking false branch
if (meshset.isValid() == false)
^
/builds/ben.boeckel/smtk/build/../smtk/mesh/operators/ExtractByDihedralAngle.cxx:164:3: note: 'shellCreated' declared without an initial value
bool shellCreated;
^
/builds/ben.boeckel/smtk/build/../smtk/mesh/operators/ExtractByDihedralAngle.cxx:165:7: note: Assuming the condition is false
if (smtk::mesh::utility::highestDimension(surfaceMesh) == smtk::mesh::Dims3)
^
/builds/ben.boeckel/smtk/build/../smtk/mesh/operators/ExtractByDihedralAngle.cxx:165:3: note: Taking false branch
if (smtk::mesh::utility::highestDimension(surfaceMesh) == smtk::mesh::Dims3)
^
/builds/ben.boeckel/smtk/build/../smtk/mesh/operators/ExtractByDihedralAngle.cxx:197:5: note: Loop condition is false. Execution continues on line 203
for (auto i = smtk::mesh::rangeElementsBegin(newCells);
^
/builds/ben.boeckel/smtk/build/../smtk/mesh/operators/ExtractByDihedralAngle.cxx:206:9: note: Assuming the condition is true
if (toCheck.empty())
^
/builds/ben.boeckel/smtk/build/../smtk/mesh/operators/ExtractByDihedralAngle.cxx:206:5: note: Taking true branch
if (toCheck.empty())
^
/builds/ben.boeckel/smtk/build/../smtk/mesh/operators/ExtractByDihedralAngle.cxx:208:7: note: Execution continues on line 222
break;
^
/builds/ben.boeckel/smtk/build/../smtk/mesh/operators/ExtractByDihedralAngle.cxx:222:7: note: Branch condition evaluates to a garbage value
if (shellCreated)
^
/builds/ben.boeckel/smtk/build/../smtk/attribute/Definition.cxx:122:21: warning: Value stored to 'def' during its initialization is never read [clang-analyzer-deadcode.DeadStores]
const Definition* def = this;
^
/builds/ben.boeckel/smtk/build/../smtk/attribute/Definition.cxx:122:21: note: Value stored to 'def' during its initialization is never read
/builds/ben.boeckel/smtk/build/../smtk/mesh/moab/Interface.cxx:1262:5: warning: Value stored to 'rval' is never read [clang-analyzer-deadcode.DeadStores]
rval = m_iface->tag_set_data(btag.moabTag(), moabMeshsets, boolean_tag_values);
^
/builds/ben.boeckel/smtk/build/../smtk/mesh/moab/Interface.cxx:1262:5: note: Value stored to 'rval' is never read
/builds/ben.boeckel/smtk/build/../smtk/mesh/moab/Interface.cxx:1610:5: warning: Value stored to 'rval' is never read [clang-analyzer-deadcode.DeadStores]
rval = m_iface->tag_set_data(btag.moabTag(), moabMeshsets, boolean_tag_values);
^
/builds/ben.boeckel/smtk/build/../smtk/mesh/moab/Interface.cxx:1610:5: note: Value stored to 'rval' is never read
/builds/ben.boeckel/smtk/build/../smtk/model/operators/AddAuxiliaryGeometry.cxx:152:7: warning: Value stored to 'haveBBox' is never read [clang-analyzer-deadcode.DeadStores]
haveBBox = true;
^
/builds/ben.boeckel/smtk/build/../smtk/model/operators/AddAuxiliaryGeometry.cxx:152:7: note: Value stored to 'haveBBox' is never read
/builds/ben.boeckel/smtk/build/../smtk/attribute/ReferenceItem.cxx:221:11: warning: Call to virtual function during destruction [clang-analyzer-optin.cplusplus.VirtualCall]
if (this->isSet(i))
^
/builds/ben.boeckel/smtk/build/../smtk/attribute/ReferenceItem.cxx:216:3: note: Taking true branch
if (myAtt != nullptr)
^
/builds/ben.boeckel/smtk/build/../smtk/attribute/ReferenceItem.cxx:219:17: note: Assuming 'i' is < 'n'
for (i = 0; i < n; i++)
^
/builds/ben.boeckel/smtk/build/../smtk/attribute/ReferenceItem.cxx:219:5: note: Loop condition is true. Entering loop body
for (i = 0; i < n; i++)
^
/builds/ben.boeckel/smtk/build/../smtk/attribute/ReferenceItem.cxx:221:11: note: This destructor of an object of type '~ReferenceItem' has not returned when the virtual method was called
if (this->isSet(i))
^
/builds/ben.boeckel/smtk/build/../smtk/attribute/ReferenceItem.cxx:221:11: note: Call to virtual function during destruction
/builds/ben.boeckel/smtk/build/../smtk/attribute/ReferenceItem.cxx:223:9: warning: Call to virtual function during destruction [clang-analyzer-optin.cplusplus.VirtualCall]
this->unset(i);
^
/builds/ben.boeckel/smtk/build/../smtk/attribute/ReferenceItem.cxx:216:3: note: Taking true branch
if (myAtt != nullptr)
^
/builds/ben.boeckel/smtk/build/../smtk/attribute/ReferenceItem.cxx:219:17: note: Assuming 'i' is < 'n'
for (i = 0; i < n; i++)
^
/builds/ben.boeckel/smtk/build/../smtk/attribute/ReferenceItem.cxx:219:5: note: Loop condition is true. Entering loop body
for (i = 0; i < n; i++)
^
/builds/ben.boeckel/smtk/build/../smtk/attribute/ReferenceItem.cxx:221:11: note: Assuming the condition is true
if (this->isSet(i))
^
/builds/ben.boeckel/smtk/build/../smtk/attribute/ReferenceItem.cxx:221:7: note: Taking true branch
if (this->isSet(i))
^
/builds/ben.boeckel/smtk/build/../smtk/attribute/ReferenceItem.cxx:223:9: note: This destructor of an object of type '~ReferenceItem' has not returned when the virtual method was called
this->unset(i);
^
/builds/ben.boeckel/smtk/build/../smtk/attribute/ReferenceItem.cxx:223:9: note: Call to virtual function during destruction
/builds/ben.boeckel/smtk/build/../smtk/attribute/ReferenceItem.cxx:411:58: warning: Call to virtual function during destruction [clang-analyzer-optin.cplusplus.VirtualCall]
auto def = static_cast<const ReferenceItemDefinition*>(this->definition().get());
^
/builds/ben.boeckel/smtk/build/../smtk/attribute/ReferenceItem.cxx:216:3: note: Taking true branch
if (myAtt != nullptr)
^
/builds/ben.boeckel/smtk/build/../smtk/attribute/ReferenceItem.cxx:219:17: note: Assuming 'i' is < 'n'
for (i = 0; i < n; i++)
^
/builds/ben.boeckel/smtk/build/../smtk/attribute/ReferenceItem.cxx:219:5: note: Loop condition is true. Entering loop body
for (i = 0; i < n; i++)
^
/builds/ben.boeckel/smtk/build/../smtk/attribute/ReferenceItem.cxx:221:7: note: Taking true branch
if (this->isSet(i))
^
/builds/ben.boeckel/smtk/build/../smtk/attribute/ReferenceItem.cxx:223:9: note: This destructor of an object of type '~ReferenceItem' has not returned when the virtual method was called
this->unset(i);
^
/builds/ben.boeckel/smtk/build/../smtk/attribute/ReferenceItem.cxx:223:9: note: Calling 'ReferenceItem::unset'
/builds/ben.boeckel/smtk/build/../smtk/attribute/ReferenceItem.cxx:537:3: note: Calling 'ReferenceItem::setObjectValue'
this->setObjectValue(i, PersistentObjectPtr());
^
/builds/ben.boeckel/smtk/build/../smtk/attribute/ReferenceItem.cxx:411:58: note: Call to virtual function during destruction
auto def = static_cast<const ReferenceItemDefinition*>(this->definition().get());
^
../smtk/model/Instance.txx:51:30: warning: Called C++ object pointer is null [clang-analyzer-core.CallAndMessage]
const auto& sourceCoords = sourceTess->coords();
^
/builds/ben.boeckel/smtk/build/../smtk/model/operators/MergeInstances.cxx:72:7: note: Assuming the condition is false
if (instances.empty())
^
/builds/ben.boeckel/smtk/build/../smtk/model/operators/MergeInstances.cxx:72:3: note: Taking false branch
if (instances.empty())
^
/builds/ben.boeckel/smtk/build/../smtk/model/operators/MergeInstances.cxx:78:3: note: Taking false branch
if (!resource)
^
/builds/ben.boeckel/smtk/build/../smtk/model/operators/MergeInstances.cxx:83:21: note: Calling 'Instance::merge'
Instance merged = Instance::merge(instances);
^
../smtk/model/Instance.txx:163:7: note: Assuming the condition is false
if (instances.empty())
^
../smtk/model/Instance.txx:163:3: note: Taking false branch
if (instances.empty())
^
../smtk/model/Instance.txx:168:7: note: Assuming the condition is false
if (instances.size() == 1)
^
../smtk/model/Instance.txx:168:3: note: Taking false branch
if (instances.size() == 1)
^
../smtk/model/Instance.txx:177:7: note: Assuming 'tess' is non-null
if (!tess)
^
../smtk/model/Instance.txx:177:3: note: Taking false branch
if (!tess)
^
../smtk/model/Instance.txx:187:12: note: Calling 'Instance::clonePlacements'
result = archetype.clonePlacements(all.begin(), all.end(), /* relate */ false);
^
../smtk/model/Instance.txx:31:3: note: Taking false branch
if (!rsrc)
^
../smtk/model/Instance.txx:37:28: note: Assigning value
const auto& sourceTess = this->hasTessellation();
^
../smtk/model/Instance.txx:37:3: note: 'sourceTess' initialized here
const auto& sourceTess = this->hasTessellation();
^
../smtk/model/Instance.txx:39:7: note: Assuming the condition is false
if (this->name().rfind("subset") == std::string::npos)
^
../smtk/model/Instance.txx:39:3: note: Taking false branch
if (this->name().rfind("subset") == std::string::npos)
^
../smtk/model/Instance.txx:43:7: note: Assuming 'sourceTess' is null
if (sourceTess)
^
../smtk/model/Instance.txx:43:3: note: Taking false branch
if (sourceTess)
^
../smtk/model/Instance.txx:51:30: note: Called C++ object pointer is null
const auto& sourceCoords = sourceTess->coords();
^
../smtk/model/Instance.txx:51:30: warning: Called C++ object pointer is null [clang-analyzer-core.CallAndMessage]
const auto& sourceCoords = sourceTess->coords();
^
/builds/ben.boeckel/smtk/build/../smtk/model/operators/DivideInstance.cxx:58:7: note: Left side of '||' is false
if (!resource || !instance.isValid())
^
/builds/ben.boeckel/smtk/build/../smtk/model/operators/DivideInstance.cxx:58:20: note: Assuming the condition is false
if (!resource || !instance.isValid())
^
/builds/ben.boeckel/smtk/build/../smtk/model/operators/DivideInstance.cxx:58:3: note: Taking false branch
if (!resource || !instance.isValid())
^
/builds/ben.boeckel/smtk/build/../smtk/model/operators/DivideInstance.cxx:70:18: note: Calling 'Instance::divide'
auto divided = instance.divide(/* merge */ false, &children);
^
../smtk/model/Instance.txx:134:37: note: Assuming 'placement' is >= 'size'
for (std::size_t placement = 0; placement < size; ++placement)
^
../smtk/model/Instance.txx:134:5: note: Loop condition is false. Execution continues on line 142
for (std::size_t placement = 0; placement < size; ++placement)
^
../smtk/model/Instance.txx:148:20: note: Calling 'Instance::clonePlacements'
Instance div = this->clonePlacements(entry.begin(), entry.end(), false);
^
../smtk/model/Instance.txx:31:3: note: Taking false branch
if (!rsrc)
^
../smtk/model/Instance.txx:37:28: note: Assigning value
const auto& sourceTess = this->hasTessellation();
^
../smtk/model/Instance.txx:37:3: note: 'sourceTess' initialized here
const auto& sourceTess = this->hasTessellation();
^
../smtk/model/Instance.txx:39:7: note: Assuming the condition is false
if (this->name().rfind("subset") == std::string::npos)
^
../smtk/model/Instance.txx:39:3: note: Taking false branch
if (this->name().rfind("subset") == std::string::npos)
^
../smtk/model/Instance.txx:43:7: note: Assuming 'sourceTess' is null
if (sourceTess)
^
../smtk/model/Instance.txx:43:3: note: Taking false branch
if (sourceTess)
^
../smtk/model/Instance.txx:51:30: note: Called C++ object pointer is null
const auto& sourceCoords = sourceTess->coords();
^
And it goes on. I'll just leave it at this list for now; we can chip away at it.
Cc: @bob.obara