+ fix flaws found with code analyzer tool

This commit is contained in:
wmayer 2014-05-07 13:09:44 +02:00
parent 94f10f5d95
commit 3b5cdda879
22 changed files with 111 additions and 119 deletions

View File

@ -123,6 +123,8 @@ DocumentObjectExecReturn *FeatureTest::execute(void)
float f;
void *s;
// Code analyzers may complain about some errors. This can be ignored
// because this is done on purpose to test the error handling mechanism
switch(ExceptionType.getValue())
{
case 0: break;
@ -131,7 +133,7 @@ DocumentObjectExecReturn *FeatureTest::execute(void)
case 3: *i=0;printf("%i",*i);break; // seg-vault
case 4: j=0; printf("%i",1/j); break; // int devision by zero
case 5: f=0.0; printf("%f",1/f); break; // float devision by zero
case 6: s = malloc(3600000000ul);break; // out-of-memory
case 6: s = malloc(3600000000ul); free(s); break; // out-of-memory
}
ExecCount.setValue(ExecCount.getValue() + 1);

View File

@ -39,7 +39,7 @@ bool Py::Vector::accepts (PyObject *obj) const
if (obj && Vector_TypeCheck (obj)) {
return true;
}
else if (PyTuple_Check(obj)) {
else if (obj && PyTuple_Check(obj)) {
return (PyTuple_Size(obj) == 3);
}

View File

@ -261,21 +261,17 @@ ByteArrayOStreambuf::seekoff(std::streambuf::off_type off,
std::ios_base::seekdir way,
std::ios_base::openmode /*mode*/)
{
off_type begpos = 0;
off_type endpos = 0;
off_type curpos = _buffer->pos();
switch (way) {
case std::ios_base::beg:
begpos = 0;
endpos = off;
break;
case std::ios_base::cur:
begpos = curpos;
endpos = begpos + off;
endpos = curpos + off;
break;
case std::ios_base::end:
begpos = _buffer->size();
endpos = begpos;
endpos = _buffer->size();
break;
default:
return pos_type(off_type(-1));
@ -401,21 +397,17 @@ IODeviceOStreambuf::seekoff(std::streambuf::off_type off,
std::ios_base::seekdir way,
std::ios_base::openmode /*mode*/)
{
off_type begpos = 0;
off_type endpos = 0;
off_type curpos = device->pos();
switch (way) {
case std::ios_base::beg:
begpos = 0;
endpos = off;
break;
case std::ios_base::cur:
begpos = curpos;
endpos = begpos + off;
endpos = curpos + off;
break;
case std::ios_base::end:
begpos = device->size();
endpos = begpos;
endpos = device->size();
break;
default:
return pos_type(off_type(-1));
@ -499,21 +491,17 @@ IODeviceIStreambuf::seekoff(std::streambuf::off_type off,
std::ios_base::seekdir way,
std::ios_base::openmode /*mode*/)
{
off_type begpos = 0;
off_type endpos = 0;
off_type curpos = device->pos();
switch (way) {
case std::ios_base::beg:
begpos = 0;
endpos = off;
break;
case std::ios_base::cur:
begpos = curpos;
endpos = begpos + off;
endpos = curpos + off;
break;
case std::ios_base::end:
begpos = device->size();
endpos = begpos;
endpos = device->size();
break;
default:
return pos_type(off_type(-1));

View File

@ -240,14 +240,12 @@ QPixmap BitmapFactoryInst::pixmap(const char* name) const
// try to find it in the given directories
if (icon.isNull()) {
bool found = false;
QList<QByteArray> formats = QImageReader::supportedImageFormats();
formats.prepend("SVG"); // check first for SVG to use special import mechanism
for (QStringList::ConstIterator pt = d->paths.begin(); pt != d->paths.end() && !found; ++pt) {
for (QStringList::ConstIterator pt = d->paths.begin(); pt != d->paths.end(); ++pt) {
QDir d(*pt);
QString fileName = d.filePath(fn);
if (loadPixmap(fileName, icon)) {
found = true;
break;
}
else {
@ -256,7 +254,6 @@ QPixmap BitmapFactoryInst::pixmap(const char* name) const
QString path = QString::fromAscii("%1.%2").arg(fileName).
arg(QString::fromAscii((*fm).toLower().constData()));
if (loadPixmap(path, icon)) {
found = true;
break;
}
}

View File

@ -355,7 +355,7 @@ SoFCUnifiedSelection::handleEvent(SoHandleEventAction * action)
if (vp && vp->isDerivedFrom(ViewProviderDocumentObject::getClassTypeId()))
vpd = static_cast<ViewProviderDocumentObject*>(vp);
SbBool old_state = highlighted;
//SbBool old_state = highlighted;
highlighted = FALSE;
if (vpd && vpd->useNewSelectionModel() && vpd->isSelectable()) {
std::string documentName = vpd->getObject()->getDocument()->getName();
@ -391,7 +391,7 @@ SoFCUnifiedSelection::handleEvent(SoHandleEventAction * action)
action.apply(currenthighlight);
currenthighlight->unref();
currenthighlight = 0;
old_state = !highlighted;
//old_state = !highlighted;
}
currenthighlight = static_cast<SoFullPath*>(sa.getPath()->copy());

View File

@ -204,10 +204,12 @@ void TreeWidget::contextMenuEvent (QContextMenuEvent * e)
action->setData(QByteArray((*it)->getName()));
if (*it == activeDoc) active = action;
}
if (active) active->setChecked(true);
active = subMenuGroup.checkedAction();
if (active)
active->setChecked(true);
subMenu.addActions(subMenuGroup.actions());
}
if (contextMenu.actions().count() > 0)
contextMenu.exec(QCursor::pos());
}

View File

@ -645,10 +645,9 @@ bool MeshFixDeformedFacets::Fixup()
if ( !it->IsDegenerated() )
{
// store the angles to avoid to compute twice
float fCosAngles[3];
float fCosAngles[3] = {0,0,0};
bool done=false;
// first check for angle > 120°: in this case we swap with the opposite edge
for (int i=0; i<3; i++)
{
u = it->_aclPoints[(i+1)%3]-it->_aclPoints[i];
@ -658,7 +657,12 @@ bool MeshFixDeformedFacets::Fixup()
float fCosAngle = u * v;
fCosAngles[i] = fCosAngle;
}
// first check for angle > 120°: in this case we swap with the opposite edge
for (int i=0; i<3; i++)
{
float fCosAngle = fCosAngles[i];
if (fCosAngle < -0.5f) {
const MeshFacet& face = it.GetReference();
unsigned long uNeighbour = face._aulNeighbours[(i+1)%3];

View File

@ -198,7 +198,6 @@ std::vector<unsigned long> MeshEvalOrientation::GetIndices() const
MeshFacetArray::_TConstIterator iBeg = rFAry.begin();
MeshFacetArray::_TConstIterator iEnd = rFAry.end();
ulVisited = 0;
ulStartFacet = 0;
std::vector<unsigned long> uIndices, uComplement;

View File

@ -1235,7 +1235,6 @@ bool MeshInput::LoadInventor (std::istream &rstrIn)
else if (points && line.find("INDEXEDFACESET {") != std::string::npos) {
unsigned long ulPoints[3];
facets = true;
flag = true;
unsigned long ulCt = 0;
// Get the next line and check for the index field which might begin
// with the first index already.

View File

@ -344,7 +344,6 @@ void SetOperations::TriangulateMesh (const MeshKernel &cutMesh, int side)
Vector3f dirY = dirX % normal;
// project points to 2D plane
i = 0;
std::vector<Vector3f>::iterator it;
std::vector<Vector3f> vertices;
for (it = points.begin(); it != points.end(); it++)

View File

@ -425,7 +425,6 @@ MeshFillHole::MeshFillHole(MeshHoleFiller& hf, Gui::View3DInventor* parent)
SoBaseColor * markcol = new SoBaseColor;
markcol->rgb.setValue(1.0f, 1.0f, 0.0f);
SoPointSet* marker = new SoPointSet();
myBridgeRoot->addChild(markcol);
myVertex = new SoCoordinate3();

View File

@ -1292,27 +1292,32 @@ PyObject* BSplineSurfacePy::approximate(PyObject *args)
}
}
if(continuity<0 || continuity>3){
if (continuity<0 || continuity>3) {
Standard_Failure::Raise("continuity must be between 0 and 3");
}
GeomAbs_Shape c;
switch(continuity){
case 0:
c = GeomAbs_C0;
case 1:
c = GeomAbs_C1;
case 2:
c = GeomAbs_C2;
case 3:
c = GeomAbs_C3;
}
if (interpolationPoints.RowLength() < 2 || interpolationPoints.ColLength() < 2) {
Standard_Failure::Raise("not enough points given");
}
GeomAbs_Shape c;
switch(continuity){
case 0:
c = GeomAbs_C0;
break;
case 1:
c = GeomAbs_C1;
break;
case 2:
c = GeomAbs_C2;
break;
case 3:
c = GeomAbs_C3;
break;
}
GeomAPI_PointsToBSplineSurface surInterpolation;
if(len == 5){
if (len == 5) {
surInterpolation.Init(interpolationPoints, degMin, degMax, c, tol3d);
}
else {
@ -1334,7 +1339,6 @@ PyObject* BSplineSurfacePy::approximate(PyObject *args)
PyObject* BSplineSurfacePy::interpolate(PyObject *args)
{
PyObject* obj;
Standard_Real tol3d = Precision::Approximation();
Standard_Real X0=0;
Standard_Real dX=0;
Standard_Real Y0=0;

View File

@ -165,10 +165,10 @@ PyObject* FT2FC(const Py_UNICODE *PyUString,
if (!PyList_Size(WireList)) // empty ==> whitespace
Base::Console().Log("FT2FC char '0x%04x'/'%d' has no Wires!\n", currchar, currchar);
else
PyErr = PyList_Append(CharList, WireList);
PyList_Append(CharList, WireList);
PenPos += (cadv + tracking);
prevchar = currchar;
}
}
error = FT_Done_FreeType(FTLib);
if(error) {
@ -285,7 +285,7 @@ PyObject* getGlyphContours(FT_Face FTFont, UNICHAR currchar, double PenPos, doub
if (!ctx.Edges.empty()){
ctx.Wires.push_back(edgesToWire(ctx.Edges));
}
FT_Orientation fontClass = FT_Outline_Get_Orientation(&FTFont->glyph->outline);
/*FT_Orientation fontClass =*/ FT_Outline_Get_Orientation(&FTFont->glyph->outline);
PyObject* ret = PyList_New(0);
gp_Vec pointer = gp_Vec(PenPos * Scale,0.0,0.0);
@ -301,7 +301,7 @@ PyObject* getGlyphContours(FT_Face FTFont, UNICHAR currchar, double PenPos, doub
ErrorMsg << "FT2FC OCC BRepScale failed \n";
throw std::runtime_error(ErrorMsg.str());
}
PyErr = PyList_Append(ret,new TopoShapeWirePy(new TopoShape(TopoDS::Wire(BRepScale.Shape()))));
PyList_Append(ret,new TopoShapeWirePy(new TopoShape(TopoDS::Wire(BRepScale.Shape()))));
}
return(ret);
}

View File

@ -1602,7 +1602,7 @@ PyObject* TopoShapePy::distToShape(PyObject *args)
pts = PyTuple_New(2);
PyTuple_SetItem(pts,0,pPt1);
PyTuple_SetItem(pts,1,pPt2);
int PyErr = PyList_Append(solnPts, pts);
PyList_Append(solnPts, pts);
geom = PyTuple_New(6);
PyTuple_SetItem(geom,0,pSuppType1);
@ -1611,7 +1611,7 @@ PyObject* TopoShapePy::distToShape(PyObject *args)
PyTuple_SetItem(geom,3,pSuppType2);
PyTuple_SetItem(geom,4,pSupportIndex2);
PyTuple_SetItem(geom,5,pParm2);
PyErr = PyList_Append(solnGeom, geom);
PyList_Append(solnGeom, geom);
}
}
else {

View File

@ -313,7 +313,7 @@ void DlgPrimitives::executeCallback(Picker* p)
viewer->setEditing(true);
viewer->setRedirectToSceneGraph(true);
SoNode* root = viewer->getSceneGraph();
int mode;
int mode = 0;
if (root && root->getTypeId().isDerivedFrom(Gui::SoFCUnifiedSelection::getClassTypeId())) {
mode = static_cast<Gui::SoFCUnifiedSelection*>(root)->selectionMode.getValue();
static_cast<Gui::SoFCUnifiedSelection*>(root)->selectionMode.setValue(Gui::SoFCUnifiedSelection::OFF);

View File

@ -304,8 +304,8 @@ bool TaskDlgGrooveParameters::reject()
{
// get the support and Sketch
PartDesign::Groove* pcGroove = static_cast<PartDesign::Groove*>(GrooveView->getObject());
Sketcher::SketchObject *pcSketch;
App::DocumentObject *pcSupport;
Sketcher::SketchObject *pcSketch = 0;
App::DocumentObject *pcSupport = 0;
if (pcGroove->Sketch.getValue()) {
pcSketch = static_cast<Sketcher::SketchObject*>(pcGroove->Sketch.getValue());
pcSupport = pcSketch->Support.getValue();

View File

@ -528,8 +528,8 @@ bool TaskDlgPadParameters::reject()
{
// get the support and Sketch
PartDesign::Pad* pcPad = static_cast<PartDesign::Pad*>(PadView->getObject());
Sketcher::SketchObject *pcSketch;
App::DocumentObject *pcSupport;
Sketcher::SketchObject *pcSketch = 0;
App::DocumentObject *pcSupport = 0;
if (pcPad->Sketch.getValue()) {
pcSketch = static_cast<Sketcher::SketchObject*>(pcPad->Sketch.getValue());
pcSupport = pcSketch->Support.getValue();

View File

@ -482,8 +482,8 @@ bool TaskDlgPocketParameters::reject()
{
// get the support and Sketch
PartDesign::Pocket* pcPocket = static_cast<PartDesign::Pocket*>(PocketView->getObject());
Sketcher::SketchObject *pcSketch;
App::DocumentObject *pcSupport;
Sketcher::SketchObject *pcSketch = 0;
App::DocumentObject *pcSupport = 0;
if (pcPocket->Sketch.getValue()) {
pcSketch = static_cast<Sketcher::SketchObject*>(pcPocket->Sketch.getValue());
pcSupport = pcSketch->Support.getValue();

View File

@ -304,8 +304,8 @@ bool TaskDlgRevolutionParameters::reject()
{
// get the support and Sketch
PartDesign::Revolution* pcRevolution = static_cast<PartDesign::Revolution*>(RevolutionView->getObject());
Sketcher::SketchObject *pcSketch;
App::DocumentObject *pcSupport;
Sketcher::SketchObject *pcSketch = 0;
App::DocumentObject *pcSupport = 0;
if (pcRevolution->Sketch.getValue()) {
pcSketch = static_cast<Sketcher::SketchObject*>(pcRevolution->Sketch.getValue());
pcSupport = pcSketch->Support.getValue();

View File

@ -102,60 +102,59 @@ void CmdRaytracingWriteCamera::activated(int iMsg)
if (ret != QMessageBox::Yes)
return;
}
SoInput in;
in.setBuffer((void*)ppReturn,std::strlen(ppReturn));
SoNode* rootNode;
SoDB::read(&in,rootNode);
if (!rootNode || !rootNode->getTypeId().isDerivedFrom(SoCamera::getClassTypeId()))
throw Base::Exception("CmdRaytracingWriteCamera::activated(): Could not read "
"camera information from ASCII stream....\n");
// root-node returned from SoDB::readAll() has initial zero
// ref-count, so reference it before we start using it to
// avoid premature destruction.
SoCamera * Cam = static_cast<SoCamera*>(rootNode);
Cam->ref();
SbRotation camrot = Cam->orientation.getValue();
SbVec3f upvec(0, 1, 0); // init to default up vector
camrot.multVec(upvec, upvec);
SbVec3f lookat(0, 0, -1); // init to default view direction vector
camrot.multVec(lookat, lookat);
SbVec3f pos = Cam->position.getValue();
float Dist = Cam->focalDistance.getValue();
QStringList filter;
filter << QObject::tr("Povray(*.pov)");
filter << QObject::tr("All Files (*.*)");
QString fn = Gui::FileDialog::getSaveFileName(Gui::getMainWindow(), QObject::tr("Export page"), QString(), filter.join(QLatin1String(";;")));
if (fn.isEmpty())
return;
std::string cFullName = (const char*)fn.toUtf8();
// building up the python string
std::stringstream out;
out << "Raytracing.writeCameraFile(\"" << strToPython(cFullName) << "\","
<< "(" << pos.getValue()[0] <<"," << pos.getValue()[1] <<"," << pos.getValue()[2] <<"),"
<< "(" << lookat.getValue()[0] <<"," << lookat.getValue()[1] <<"," << lookat.getValue()[2] <<")," ;
lookat *= Dist;
lookat += pos;
out << "(" << lookat.getValue()[0] <<"," << lookat.getValue()[1] <<"," << lookat.getValue()[2] <<"),"
<< "(" << upvec.getValue()[0] <<"," << upvec.getValue()[1] <<"," << upvec.getValue()[2] <<") )" ;
doCommand(Doc,"import Raytracing");
doCommand(Gui,out.str().c_str());
// Bring ref-count of root-node back to zero to cause the
// destruction of the camera.
Cam->unref();
}
SoInput in;
in.setBuffer((void*)ppReturn,std::strlen(ppReturn));
SoNode* rootNode;
SoDB::read(&in,rootNode);
if (!rootNode || !rootNode->getTypeId().isDerivedFrom(SoCamera::getClassTypeId()))
throw Base::Exception("CmdRaytracingWriteCamera::activated(): Could not read "
"camera information from ASCII stream....\n");
// root-node returned from SoDB::readAll() has initial zero
// ref-count, so reference it before we start using it to
// avoid premature destruction.
SoCamera * Cam = static_cast<SoCamera*>(rootNode);
Cam->ref();
SbRotation camrot = Cam->orientation.getValue();
SbVec3f upvec(0, 1, 0); // init to default up vector
camrot.multVec(upvec, upvec);
SbVec3f lookat(0, 0, -1); // init to default view direction vector
camrot.multVec(lookat, lookat);
SbVec3f pos = Cam->position.getValue();
float Dist = Cam->focalDistance.getValue();
QStringList filter;
filter << QObject::tr("Povray(*.pov)");
filter << QObject::tr("All Files (*.*)");
QString fn = Gui::FileDialog::getSaveFileName(Gui::getMainWindow(), QObject::tr("Export page"), QString(), filter.join(QLatin1String(";;")));
if (fn.isEmpty())
return;
std::string cFullName = (const char*)fn.toUtf8();
// building up the python string
std::stringstream out;
out << "Raytracing.writeCameraFile(\"" << strToPython(cFullName) << "\","
<< "(" << pos.getValue()[0] <<"," << pos.getValue()[1] <<"," << pos.getValue()[2] <<"),"
<< "(" << lookat.getValue()[0] <<"," << lookat.getValue()[1] <<"," << lookat.getValue()[2] <<")," ;
lookat *= Dist;
lookat += pos;
out << "(" << lookat.getValue()[0] <<"," << lookat.getValue()[1] <<"," << lookat.getValue()[2] <<"),"
<< "(" << upvec.getValue()[0] <<"," << upvec.getValue()[1] <<"," << upvec.getValue()[2] <<") )" ;
doCommand(Doc,"import Raytracing");
doCommand(Gui,out.str().c_str());
// Bring ref-count of root-node back to zero to cause the
// destruction of the camera.
Cam->unref();
}
bool CmdRaytracingWriteCamera::isActive(void)

View File

@ -1245,8 +1245,8 @@ int Sketch::addDistanceConstraint(int geoId, double value)
// line to line distance constraint
int Sketch::addDistanceConstraint(int geoId1, int geoId2, double value)
{
geoId1 = checkGeoId(geoId1);
geoId2 = checkGeoId(geoId2);
//geoId1 = checkGeoId(geoId1);
//geoId2 = checkGeoId(geoId2);
//assert(Geoms[geoId1].type == Line);
//assert(Geoms[geoId2].type == Line);

View File

@ -158,7 +158,7 @@ System::System(std::vector<Constraint *> clist_)
// create own (shallow) copy of constraints
for (std::vector<Constraint *>::iterator constr=clist_.begin();
constr != clist_.end(); ++constr) {
Constraint *newconstr;
Constraint *newconstr = 0;
switch ((*constr)->getTypeId()) {
case Equal: {
ConstraintEqual *oldconstr = static_cast<ConstraintEqual *>(*constr);