Core: Fix several coverity issues:

* CID 350582: Big parameter passed by value
* CID 350639: Big parameter passed by value
* CID 305234: Uncaught exception
* CID 316529: Uncaught exception
* CID 350597: Uncaught exception
* CID 350623: Uncaught exception
* CID 332690: Uncaught exception
* CID 332700: Unchecked return value
* CID 350576: Uninitialized scalar field
* CID 350587: Uninitialized scalar variable
* CID 192606: Uninitialized scalar field
* CID 332699: Uninitialized pointer field
* CID 350561: Dereference null return value
* CID 350610: Dereference null return value
* CID 350567: Dereference after null check
This commit is contained in:
wmayer
2022-03-13 13:53:32 +01:00
parent 2e6c4373bf
commit b78dc894e1
14 changed files with 94 additions and 48 deletions

View File

@@ -315,7 +315,7 @@ void App::Metadata::addGenericMetadata(const std::string& tag, const Meta::Gener
void App::Metadata::removeContentItem(const std::string& tag, const std::string& itemName)
{
auto tagRange = _content.equal_range(tag);
auto foundItem = std::find_if(tagRange.first, tagRange.second, [itemName](auto check) -> bool { return itemName == check.second.name(); });
auto foundItem = std::find_if(tagRange.first, tagRange.second, [&itemName](auto check) -> bool { return itemName == check.second.name(); });
if (foundItem != tagRange.second)
_content.erase(foundItem);
}
@@ -686,6 +686,8 @@ Meta::Url::Url(const XERCES_CPP_NAMESPACE::DOMElement* e)
type = UrlType::readme;
else if (typeAttribute == "documentation")
type = UrlType::documentation;
else
type = UrlType::website;
if (type == UrlType::repository)
branch = StrXUTF8(e->getAttribute(XUTF8Str("branch").unicodeForm())).str;

View File

@@ -80,7 +80,7 @@ public:
typedef boost::function<std::string (const App::ObjectIdentifier & path, std::shared_ptr<const App::Expression> expr)> ValidatorFunc;
/**
* @brief The ExpressionInfo struct encapsulates an expression and a comment.
* @brief The ExpressionInfo struct encapsulates an expression.
*/
struct ExpressionInfo {
@@ -94,10 +94,12 @@ public:
ExpressionInfo(const ExpressionInfo & other) {
expression = other.expression;
busy = other.busy;
}
ExpressionInfo & operator=(const ExpressionInfo & other) {
expression = other.expression;
busy = other.busy;
return *this;
}
};

View File

@@ -235,7 +235,8 @@ PyObject* createWeakRef(PyObjectBase* ptr)
static bool init = false;
if (!init) {
init = true;
PyType_Ready(&PyBaseProxyType);
if (PyType_Ready(&PyBaseProxyType) < 0)
return nullptr;
}
PyObject* proxy = ptr->baseProxy;

View File

@@ -353,7 +353,7 @@ void DlgGeneralImp::recreatePreferencePackMenu()
ui->PreferencePacks->setItem(row, 1, kind);
auto button = new QPushButton(icon, tr("Apply"));
button->setToolTip(tr("Apply the %1 preference pack").arg(QString::fromStdString(pack.first)));
connect(button, &QPushButton::clicked, this, [this, pack]() { onLoadPreferencePackClicked(pack.first); });
connect(button, &QPushButton::clicked, this, [this, &pack]() { onLoadPreferencePackClicked(pack.first); });
ui->PreferencePacks->setCellWidget(row, 2, button);
++row;
}

View File

@@ -473,7 +473,12 @@ void DlgPropertyLink::detachObserver() {
auto view = qobject_cast<Gui::PropertyView*>(parentView.data());
if(view && savedSelections.size()) {
Gui::Selection().clearSelection();
try {
Gui::Selection().clearSelection();
}
catch (Py::Exception& e) {
e.clear();
}
for(auto &sel : savedSelections) {
if(sel.getSubObject())
Gui::Selection().addSelection(sel.getDocumentName().c_str(),

View File

@@ -93,7 +93,7 @@ namespace Gui {
class NS::Event : public sc::event<NS::Event>
{
public:
Event():inventor_event(nullptr), flags(new Flags){}
Event():inventor_event(nullptr), modifiers{}, flags(new Flags){}
virtual ~Event(){}
void log() const {

View File

@@ -147,10 +147,10 @@ EventFilter::eventFilter(QObject * obj, QEvent * qevent)
case QEvent::MouseButtonPress:
case QEvent::MouseButtonRelease:
case QEvent::MouseButtonDblClick:
PRIVATE(this)->trackPointerPosition(dynamic_cast<QMouseEvent *>(qevent));
PRIVATE(this)->trackPointerPosition(static_cast<QMouseEvent *>(qevent));
break;
case QEvent::Resize:
PRIVATE(this)->trackWindowSize(dynamic_cast<QResizeEvent *>(qevent));
PRIVATE(this)->trackWindowSize(static_cast<QResizeEvent *>(qevent));
break;
default:
break;

View File

@@ -83,7 +83,12 @@ QuarterWidgetP::QuarterWidgetP(QuarterWidget * masterptr, const QtGLWidget * sha
clearzbuffer(true),
clearwindow(true),
addactions(true),
processdelayqueue(true),
currentStateMachine(nullptr),
device_pixel_ratio(1.0),
transparencytypegroup(nullptr),
stereomodegroup(nullptr),
rendermodegroup(nullptr),
contextmenu(nullptr)
{
this->cachecontext = findCacheContext(masterptr, sharewidget);

View File

@@ -160,35 +160,42 @@ void SoFCSelection::doAction(SoAction *action)
if(useNewSelection.getValue() && action->getCurPathCode()!=SoAction::OFF_PATH) {
if (action->getTypeId() == Gui::SoHighlightElementAction::getClassTypeId()) {
Gui::SoHighlightElementAction* hlaction = static_cast<Gui::SoHighlightElementAction*>(action);
if(!hlaction->isHighlighted()) {
if (!hlaction->isHighlighted()) {
auto ctx = Gui::SoFCSelectionRoot::getActionContext(action,this,selContext,false);
if(ctx->isHighlighted()) {
if (ctx && ctx->isHighlighted()) {
ctx->highlightIndex = -1;
touch();
}
}else{
}
else {
auto ctx = Gui::SoFCSelectionRoot::getActionContext(action,this,selContext);
ctx->highlightColor = hlaction->getColor();
if(!ctx->isHighlighted()) {
ctx->highlightIndex = 0;
touch();
if (ctx) {
ctx->highlightColor = hlaction->getColor();
if (!ctx->isHighlighted()) {
ctx->highlightIndex = 0;
touch();
}
}
}
return;
} else if (action->getTypeId() == Gui::SoSelectionElementAction::getClassTypeId()) {
}
else if (action->getTypeId() == Gui::SoSelectionElementAction::getClassTypeId()) {
Gui::SoSelectionElementAction* selaction = static_cast<Gui::SoSelectionElementAction*>(action);
if (selaction->getType() == Gui::SoSelectionElementAction::All ||
selaction->getType() == Gui::SoSelectionElementAction::Append) {
SelContextPtr ctx = Gui::SoFCSelectionRoot::getActionContext(action,this,selContext);
ctx->selectionColor = selaction->getColor();
if(!ctx->isSelectAll()) {
ctx->selectAll();
this->touch();
if (ctx) {
ctx->selectionColor = selaction->getColor();
if(!ctx->isSelectAll()) {
ctx->selectAll();
this->touch();
}
}
} else if (selaction->getType() == Gui::SoSelectionElementAction::None ||
selaction->getType() == Gui::SoSelectionElementAction::Remove) {
}
else if (selaction->getType() == Gui::SoSelectionElementAction::None ||
selaction->getType() == Gui::SoSelectionElementAction::Remove) {
SelContextPtr ctx = Gui::SoFCSelectionRoot::getActionContext(action,this,selContext,false);
if(ctx && ctx->isSelected()) {
if (ctx && ctx->isSelected()) {
ctx->selectionIndex.clear();
this->touch();
}
@@ -965,9 +972,11 @@ SoFCSelection::setOverride(SoGLRenderAction * action, SelContextPtr ctx)
Styles mystyle = (Styles) this->style.getValue();
if(mystyle == SoFCSelection::BOX) {
SoFCSelectionRoot::renderBBox(
action,this,preselected?ctx->highlightColor:ctx->selectionColor);
if (mystyle == SoFCSelection::BOX) {
if (ctx) {
SoFCSelectionRoot::renderBBox(
action, this, preselected ? ctx->highlightColor : ctx->selectionColor);
}
this->uniqueId = oldId;
return false;
}
@@ -979,19 +988,19 @@ SoFCSelection::setOverride(SoGLRenderAction * action, SelContextPtr ctx)
SoMaterialBindingElement::set(state,SoMaterialBindingElement::OVERALL);
SoOverrideElement::setMaterialBindingOverride(state,this,true);
if(!preselected)
if (!preselected && ctx)
SoLazyElement::setEmissive(state, &ctx->selectionColor);
else
else if (ctx)
SoLazyElement::setEmissive(state, &ctx->highlightColor);
SoOverrideElement::setEmissiveColorOverride(state, this, true);
if(SoLazyElement::getLightModel(state)==SoLazyElement::BASE_COLOR
|| mystyle == SoFCSelection::EMISSIVE_DIFFUSE)
{
if(!preselected)
SoLazyElement::setDiffuse(state, this,1, &ctx->selectionColor,&colorpacker);
else
SoLazyElement::setDiffuse(state, this,1, &ctx->highlightColor,&colorpacker);
if (!preselected && ctx)
SoLazyElement::setDiffuse(state, this, 1, &ctx->selectionColor,&colorpacker);
else if (ctx)
SoLazyElement::setDiffuse(state, this, 1, &ctx->highlightColor,&colorpacker);
SoOverrideElement::setDiffuseColorOverride(state, this, true);
}

View File

@@ -367,14 +367,7 @@ TaskDialogPython::~TaskDialogPython()
Content.clear();
Base::PyGILStateLocker lock;
// The widgets stored in the 'form' attribute will be deleted.
// Thus, set this attribute to None to make sure that when using
// the same dialog instance for a task panel won't segfault.
if (this->dlg.hasAttr(std::string("form"))) {
this->dlg.setAttr(std::string("form"), Py::None());
}
this->dlg = Py::None();
clearForm();
// Assigning None to 'dlg' may destroy some of the stored widgets.
// By guarding them with QPointer their pointers will be set to null
@@ -382,6 +375,22 @@ TaskDialogPython::~TaskDialogPython()
Content.insert(Content.begin(), guarded.begin(), guarded.end());
}
void TaskDialogPython::clearForm()
{
try {
// The widgets stored in the 'form' attribute will be deleted.
// Thus, set this attribute to None to make sure that when using
// the same dialog instance for a task panel won't segfault.
if (this->dlg.hasAttr(std::string("form"))) {
this->dlg.setAttr(std::string("form"), Py::None());
}
this->dlg = Py::None();
}
catch (Py::AttributeError& e) {
e.clear();
}
}
void TaskDialogPython::open()
{
Base::PyGILStateLocker lock;

View File

@@ -104,7 +104,10 @@ public:
virtual bool reject();
/// is called by the framework if the user press the help button
virtual void helpRequested();
private:
void clearForm();
private:
Py::Object dlg;
};

View File

@@ -2744,6 +2744,9 @@ void ViewProviderLink::updateLinks(ViewProvider *vp) {
catch (const Base::TypeError &e) {
e.ReportException();
}
catch (const Base::ValueError &e) {
e.ReportException();
}
}
PyObject *ViewProviderLink::getPyObject() {

View File

@@ -283,7 +283,12 @@ ViewProviderPythonFeatureImp::~ViewProviderPythonFeatureImp()
#undef FC_PY_ELEMENT
#define FC_PY_ELEMENT(_name) py_##_name = Py::None();
FC_PY_VIEW_OBJECT
try {
FC_PY_VIEW_OBJECT
}
catch (Py::Exception& e) {
e.clear();
}
}
void ViewProviderPythonFeatureImp::init(PyObject *pyobj) {

View File

@@ -4028,13 +4028,15 @@ QWidget* PropertyFileItem::createEditor(QWidget* parent, const QObject* receiver
void PropertyFileItem::setEditorData(QWidget *editor, const QVariant& data) const
{
const App::Property* prop = getFirstProperty();
const App::PropertyFile* propFile = static_cast<const App::PropertyFile*>(prop);
std::string filter = propFile->getFilter();
Gui::FileChooser *fc = qobject_cast<Gui::FileChooser*>(editor);
if (!filter.empty()) {
fc->setFilter(Base::Tools::fromStdString(filter));
if (prop) {
const App::PropertyFile* propFile = static_cast<const App::PropertyFile*>(prop);
std::string filter = propFile->getFilter();
Gui::FileChooser *fc = qobject_cast<Gui::FileChooser*>(editor);
if (!filter.empty()) {
fc->setFilter(Base::Tools::fromStdString(filter));
}
fc->setFileName(data.toString());
}
fc->setFileName(data.toString());
}
QVariant PropertyFileItem::editorData(QWidget *editor) const