Fix several coverity issues:

* CID 350617: Dereference after null check
* CID 350585: Out-of-bounds read
* CID 350624: Resource leak
* CID 332701: Uncaught exception
* CID 350642: Uninitialized scalar field
* CID 350590: Uninitialized scalar field
* CID 350629: Uninitialized scalar variable
* CID 350602: Uninitialized scalar variable
* CID 350564: Uninitialized scalar variable
* CID 350548: Uninitialized scalar variable
This commit is contained in:
wmayer
2022-03-13 12:12:49 +01:00
parent 02bd57ac82
commit 68b92c504f
11 changed files with 85 additions and 58 deletions

View File

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

View File

@@ -36,17 +36,23 @@ using namespace App;
// Material
//===========================================================================
Material::Material()
: shininess{0.2000f}
, transparency{}
{
setType(STEEL);
setType(USER_DEFINED);
}
Material::Material(const char* MatName)
: shininess{0.2000f}
, transparency{}
{
set(MatName);
}
Material::Material(const MaterialType MatType)
: shininess{0.2000f}
, transparency{}
{
setType(MatType);
}

View File

@@ -50,7 +50,7 @@ std::string MetadataPy::representation(void) const
PyObject* MetadataPy::PyMake(struct _typeobject*, PyObject* args, PyObject*) // Python wrapper
{
// create a new instance of MetadataPy and the Twin object
// create a new instance of MetadataPy and the Twin object
const char* filename;
if (!PyArg_ParseTuple(args, "s", &filename))
return nullptr;
@@ -75,13 +75,13 @@ int MetadataPy::PyInit(PyObject* args, PyObject* /*kwd*/)
PyErr_Clear();
const char* file;
if (PyArg_ParseTuple(args, "s", &file)) {
App::Metadata* a = new Metadata(file);
*(getMetadataPtr()) = *a;
App::Metadata a(file);
*(getMetadataPtr()) = a;
return 0;
}
// Copy constructor
PyErr_Clear();
PyErr_Clear();
PyObject* o;
if (PyArg_ParseTuple(args, "O!", &(App::MetadataPy::Type), &o)) {
App::Metadata* a = static_cast<App::MetadataPy*>(o)->getMetadataPtr();

View File

@@ -103,6 +103,8 @@ TimeInfo TimeInfo::null()
TimeInfo ti;
ti.timebuffer.time = 0;
ti.timebuffer.millitm = 0;
ti.timebuffer.timezone = 0;
ti.timebuffer.dstflag = 0;
return ti;
}

View File

@@ -2516,11 +2516,13 @@ bool StdViewZoomOut::isActive(void)
{
return (qobject_cast<View3DInventor*>(getMainWindow()->activeWindow()));
}
class SelectionCallbackHandler {
namespace {
class SelectionCallbackHandler {
private:
static std::unique_ptr<SelectionCallbackHandler> currentSelectionHandler;
QCursor* prevSelectionCursor;
QCursor prevSelectionCursor;
typedef void (*FnCb)(void * userdata, SoEventCallback * node);
FnCb fnCb;
void* userData;
@@ -2531,7 +2533,8 @@ public:
// Takes the viewer, a selection mode, a cursor, a function pointer to be called on success and a void pointer for user data to be passed to the given function.
// The selection handler class stores all necessary previous states, registers a event callback and starts the selection in the given mode.
// If there is still a selection handler active, this call will generate a message and returns.
static void Create(View3DInventorViewer* viewer, View3DInventorViewer::SelectionMode selectionMode, const QCursor& cursor, FnCb doFunction= NULL, void* ud=NULL)
static void Create(View3DInventorViewer* viewer, View3DInventorViewer::SelectionMode selectionMode,
const QCursor& cursor, FnCb doFunction= nullptr, void* ud=nullptr)
{
if (currentSelectionHandler)
{
@@ -2544,7 +2547,7 @@ public:
{
currentSelectionHandler->userData = ud;
currentSelectionHandler->fnCb = doFunction;
currentSelectionHandler->prevSelectionCursor = new QCursor(viewer->cursor());
currentSelectionHandler->prevSelectionCursor = viewer->cursor();
viewer->setEditingCursor(cursor);
viewer->addEventCallback(SoEvent::getClassTypeId(),
SelectionCallbackHandler::selectionCallback, currentSelectionHandler.get());
@@ -2552,9 +2555,11 @@ public:
viewer->setSelectionEnabled(false);
viewer->startSelection(selectionMode);
}
};
}
void* getUserData() { return userData; };
void* getUserData() const {
return userData;
}
// Implements the event handler. In the normal case the provided function is called.
// Also supports aborting the selection mode by pressing (releasing) the Escape key.
@@ -2571,11 +2576,11 @@ public:
const SoKeyboardEvent * ke = static_cast<const SoKeyboardEvent*>(ev);
const SbBool press = ke->getState() == SoButtonEvent::DOWN ? true : false;
if (ke->getKey() == SoKeyboardEvent::ESCAPE) {
if (!press) {
if (!press) {
view->abortSelection();
restoreState(selectionHandler, view);
}
}
}
}
else if (ev->isOfType(SoMouseButtonEvent::getClassTypeId())) {
@@ -2586,7 +2591,8 @@ public:
if (mbe->getButton() == SoMouseButtonEvent::BUTTON1 && mbe->getState() == SoButtonEvent::UP)
{
if (selectionHandler && selectionHandler->fnCb) selectionHandler->fnCb(selectionHandler->getUserData(), n);
if (selectionHandler && selectionHandler->fnCb)
selectionHandler->fnCb(selectionHandler->getUserData(), n);
restoreState(selectionHandler, view);
}
// No other mouse events available from Coin3D to implement right mouse up abort
@@ -2595,14 +2601,18 @@ public:
static void restoreState(SelectionCallbackHandler * selectionHandler, View3DInventorViewer* view)
{
if(selectionHandler) selectionHandler->fnCb = NULL;
view->setEditingCursor(*selectionHandler->prevSelectionCursor);
view->removeEventCallback(SoEvent::getClassTypeId(), SelectionCallbackHandler::selectionCallback, selectionHandler);
view->setSelectionEnabled(selectionHandler->prevSelectionEn);
if (selectionHandler)
{
selectionHandler->fnCb = nullptr;
view->setEditingCursor(selectionHandler->prevSelectionCursor);
view->removeEventCallback(SoEvent::getClassTypeId(), SelectionCallbackHandler::selectionCallback, selectionHandler);
view->setSelectionEnabled(selectionHandler->prevSelectionEn);
}
Application::Instance->commandManager().testActive();
currentSelectionHandler = NULL;
currentSelectionHandler = nullptr;
}
};
}
std::unique_ptr<SelectionCallbackHandler> SelectionCallbackHandler::currentSelectionHandler = std::unique_ptr<SelectionCallbackHandler>();
//===========================================================================

View File

@@ -2873,7 +2873,7 @@ void View3DInventorViewer::animatedViewAll(int steps, int ms)
if (sphere.getRadius() == 0)
return;
SbVec3f direction, pos;
SbVec3f direction, pos(0.0f, 0.0f, 0.0f);
camrot.multVec(SbVec3f(0, 0, -1), direction);
bool isOrthographic = false;

View File

@@ -1321,7 +1321,7 @@ Py::Object View3DInventorPy::dumpNode(const Py::Tuple& args)
}
//FIXME: Once View3DInventor inherits from PropertyContainer we can use PropertyEnumeration.
const char* StereoTypeEnums[]= {"None","Anaglyph","QuadBuffer","InterleavedRows","InterleavedColumns",NULL};
const char* StereoTypeEnums[]= {"Mono","Anaglyph","QuadBuffer","InterleavedRows","InterleavedColumns",nullptr};
Py::Object View3DInventorPy::setStereoType(const Py::Tuple& args)
{
@@ -1370,7 +1370,9 @@ Py::Object View3DInventorPy::getStereoType(const Py::Tuple& args)
throw Py::Exception();
try {
int mode = (int)(getView3DIventorPtr()->getViewer()->stereoMode());
int mode = int(getView3DIventorPtr()->getViewer()->stereoMode());
if (mode < 0 || mode > 4)
throw Py::ValueError("Invalid stereo mode");
return Py::String(StereoTypeEnums[mode]);
}
catch (const Base::Exception& e) {

View File

@@ -371,7 +371,6 @@ void PartGui::DlgProjectionOnSurface::store_current_selected_parts(std::vector<S
auto parentShape = currentShapeStore.inputShape;
for (auto itName = selObj.front().getSubNames().begin(); itName != selObj.front().getSubNames().end(); ++itName)
{
std::string parentName = aPart->getNameInDocument();
auto currentShape = aPart->Shape.getShape().getSubShape(itName->c_str());
transform_shape_to_global_position(currentShape, aPart);

View File

@@ -89,11 +89,11 @@ private:
std::vector<TopoDS_Wire> aProjectedWireInParametricSpaceVec;
TopoDS_Face aProjectedFace;
TopoDS_Shape aProjectedSolid;
Part::Feature* partFeature;
Part::Feature* partFeature = nullptr;
std::string partName;
bool is_selectable;
long transparency;
float exrudeValue;
bool is_selectable = false;
long transparency = 0;
float exrudeValue = 0.0f;
};
//from Gui::SelectionObserver

View File

@@ -137,18 +137,21 @@ void Robot6Axis::readKinematic(const char * FileName)
{
char buf[120];
std::ifstream in(FileName);
if(!in)return;
if (!in)
return;
std::vector<std::string> destination;
AxisDefinition temp[6];
// over read the header
in.getline(buf,119,'\n');
// read 6 Axis
for( int i = 0; i<6; i++){
for (int i = 0; i < 6; i++) {
in.getline(buf,79,'\n');
destination.clear();
split(std::string(buf),',',destination);
if(destination.size() < 8) continue;
if (destination.size() < 8)
continue;
// transfer the values in kinematic structure
temp[i].a = atof(destination[0].c_str());
temp[i].alpha = atof(destination[1].c_str());

View File

@@ -23,26 +23,27 @@
#ifndef ROBOT_ROBOT6AXLE_H
#define ROBOT_ROBOT6AXLE_H
#include "kdl_cp/chain.hpp"
#include "kdl_cp/jntarray.hpp"
#include <Base/Persistence.h>
#include <Base/Placement.h>
#include <Mod/Robot/RobotGlobal.h>
namespace Robot
{
/// Definition of the Axis properties
struct AxisDefinition {
double a; // a of the Denavit-Hartenberg parameters (mm)
double alpha; // alpha of the Denavit-Hartenberg parameters (°)
double d; // d of the Denavit-Hartenberg parameters (mm)
double theta; // a of the Denavit-Hartenberg parameters (°)
double rotDir; // rotational direction (1|-1)
double maxAngle; // soft ends + in °
double minAngle; // soft ends - in °
double velocity; // max vlocity of the axle in °/s
double a = 0.0; // a of the Denavit-Hartenberg parameters (mm)
double alpha = 0.0; // alpha of the Denavit-Hartenberg parameters (°)
double d = 0.0; // d of the Denavit-Hartenberg parameters (mm)
double theta = 0.0; // a of the Denavit-Hartenberg parameters (°)
double rotDir = 0.0; // rotational direction (1|-1)
double maxAngle = 0.0; // soft ends + in °
double minAngle = 0.0; // soft ends - in °
double velocity = 0.0; // max vlocity of the axle in °/s
};
@@ -56,40 +57,39 @@ public:
Robot6Axis();
~Robot6Axis();
// from base class
// from base class
virtual unsigned int getMemSize (void) const;
virtual void Save (Base::Writer &/*writer*/) const;
virtual void Save (Base::Writer &/*writer*/) const;
virtual void Restore(Base::XMLReader &/*reader*/);
// interface
// interface
/// set the kinematic parameters of the robot
void setKinematic(const AxisDefinition KinDef[6]);
/// read the kinematic parameters of the robot from a file
void readKinematic(const char * FileName);
/// set the robot to that position, calculates the Axis
bool setTo(const Base::Placement &To);
bool setAxis(int Axis,double Value);
double getAxis(int Axis);
bool setTo(const Base::Placement &To);
bool setAxis(int Axis,double Value);
double getAxis(int Axis);
double getMaxAngle(int Axis);
double getMinAngle(int Axis);
/// calculate the new Tcp out of the Axis
bool calcTcp(void);
Base::Placement getTcp(void);
/// calculate the new Tcp out of the Axis
bool calcTcp(void);
Base::Placement getTcp(void);
//void setKinematik(const std::vector<std::vector<float> > &KinTable);
protected:
KDL::Chain Kinematic;
KDL::JntArray Actuall;
KDL::JntArray Min;
KDL::JntArray Max;
KDL::Frame Tcp;
double Velocity[6];
double RotDir [6];
KDL::Chain Kinematic;
KDL::JntArray Actuall;
KDL::JntArray Min;
KDL::JntArray Max;
KDL::Frame Tcp;
double Velocity[6];
double RotDir [6];
};
} //namespace Part