[vtk-developers] [VTK 0013389]: PVS-Studio static code analyzer for C/C++
Mantis Bug Tracker
mantis at public.kitware.com
Fri Aug 24 04:29:57 EDT 2012
The following issue has been SUBMITTED.
======================================================================
http://vtk.org/Bug/view.php?id=13389
======================================================================
Reported By: Andrey
Assigned To:
======================================================================
Project: VTK
Issue ID: 13389
Category: (No Category)
Reproducibility: have not tried
Severity: minor
Priority: normal
Status: backlog
Project: TBD
Type: incorrect functionality
Resolution: open
Fixed in Version:
======================================================================
Date Submitted: 2012-08-24 04:29 EDT
Last Modified: 2012-08-24 04:29 EDT
======================================================================
Summary: PVS-Studio static code analyzer for C/C++
Description:
I check the VTK project by using PVS-Studio -
http://www.viva64.com/en/pvs-studio/. Perhaps you would be interested.
----------------------------------
V501 There are identical sub-expressions 'newPos[2] != oldPos[2]' to the left
and to the right of the '||' operator. vtkCharts
vtkpiecewisecontrolpointsitem.cxx 129
void vtkPiecewiseControlPointsItem::SetControlPoint(vtkIdType index, double*
newPos)
{
double oldPos[4];
this->PiecewiseFunction->GetNodeValue(index, oldPos);
if (newPos[0] != oldPos[0] || newPos[1] != oldPos[1] ||
newPos[2] != oldPos[2] || newPos[2] != oldPos[2])
{
this->PiecewiseFunction->SetNodeValue(index, newPos);
}
}
----------------------------------
V501 There are identical sub-expressions to the left and to the right of the '-'
operator: outExt[0] - outExt[0] vtkFiltering vtkdatasetattributes.cxx 457
V501 There are identical sub-expressions to the left and to the right of the '-'
operator: outExt[2] - outExt[2] vtkFiltering vtkdatasetattributes.cxx 458
V501 There are identical sub-expressions to the left and to the right of the '-'
operator: outExt[4] - outExt[4] vtkFiltering vtkdatasetattributes.cxx 459
V501 There are identical sub-expressions to the left and to the right of the '-'
operator: outExt[0] - outExt[0] vtkFiltering vtkdatasetattributes.cxx 490
V501 There are identical sub-expressions to the left and to the right of the '-'
operator: outExt[2] - outExt[2] vtkFiltering vtkdatasetattributes.cxx 491
V501 There are identical sub-expressions to the left and to the right of the '-'
operator: outExt[4] - outExt[4] vtkFiltering vtkdatasetattributes.cxx 492
template <class iterT>
void vtkDataSetAttributesCopyValues(....)
{
...
inZPtr += (outExt[0]-outExt[0])*inIncs[0] * data_type_size +
(outExt[2] - outExt[2])*inIncs[1] * data_type_size +
(outExt[4] - outExt[4])*inIncs[2] * data_type_size;
...
}
Nonsensical code. This is equivalent:
inZPtr += 0;
----------------------------------
V501 There are identical sub-expressions 'this->GetMTime() > this->BuildTime' to
the left and to the right of the '||' operator. vtkFiltering
vtkdiscretizablecolortransferfunction.cxx 85
void vtkDiscretizableColorTransferFunction::Build()
{
...
if (this->Discretize &&
(this->GetMTime() > this->BuildTime ||
this->GetMTime() > this->BuildTime))
...
}
----------------------------------
V501 There are identical sub-expressions to the left and to the right of the
'||' operator: gridType == 11 || gridType == 11 vtkHybrid vtktransformtogrid.cxx
184
void vtkTransformToGrid::UpdateShiftScale()
{
int gridType = this->GridScalarType;
if (gridType == VTK_DOUBLE || gridType == VTK_DOUBLE)
...
}
----------------------------------
V501 There are identical sub-expressions to the left and to the right of the
'>=' operator: allocateExtent[1] >= allocateExtent[1] vtkImaging
vtkimagestencildata.cxx 1178
void vtkImageStencilRaster::PrepareForNewData(....)
{
...
if (allocateExtent && allocateExtent[1] >= allocateExtent[1])
...
}
----------------------------------
V501 There are identical sub-expressions '(minX > imageViewportSize[0] - 1 &&
maxX > imageViewportSize[0] - 1)' to the left and to the right of the '||'
operator. vtkVolumeRendering vtkfixedpointvolumeraycastmapper.cxx 2184
int vtkFixedPointVolumeRayCastMapper::ComputeRowBounds(....)
{
if ( ( minX < 0 && maxX < 0 ) ||
( minY < 0 && maxY < 0 ) ||
( minX > imageViewportSize[0]-1 &&
maxX > imageViewportSize[0]-1 ) ||
( minX > imageViewportSize[0]-1 &&
maxX > imageViewportSize[0]-1 ) )
...
}
----------------------------------
V501 There are identical sub-expressions '(mat[0 * 4 + 3] != 0)' to the left and
to the right of the '||' operator. vtkVolumeRendering
vtkprojectedtetrahedramapper.cxx 134
template<class point_type>
void vtkProjectedTetrahedraMapperTransformPoints(....)
{
...
if ( (mat[0*4+3] != 0) || (mat[1*4+3] != 0)
|| (mat[0*4+3] != 0) || (mat[1*4+3] != 1) )
...
}
----------------------------------
V501 There are identical sub-expressions 'sub->negNsSet->value' to the left and
to the right of the '==' operator. vtklibxml2 xmlschemas.c 13873
static int
xmlSchemaCheckCOSNSSubset(xmlSchemaWildcardPtr sub,
xmlSchemaWildcardPtr super)
{
...
if ((sub->negNsSet != NULL) &&
(super->negNsSet != NULL) &&
(sub->negNsSet->value == sub->negNsSet->value))
return (0);
...
}
----------------------------------
V517 The use of 'if (A) {...} else if (A) {...}' pattern was detected. There is
a probability of logical error presence. Check lines: 224, 227. lproj lproj.c
224
static void vprocess(FILE *fid) {
char *s;
...
if (*s == 'I' || *s == 'i') {
linvers = 1;
++s;
} else if (*s == 'I' || *s == 'i') {
linvers = 0;
++s;
} else
...
}
----------------------------------
V521 Such expressions using the ',' operator are dangerous. Make sure the
expression 'this->Internal->TableArrays[i], name' is correct. vtkIO
vtksesamereader.cxx 352
int vtkSESAMEReader::GetTableArrayStatus(const char* name)
{
...
for(i=0; i<numArrays; i++)
{
if(this->Internal->TableArrays[i], name)
{
return this->Internal->TableArrayStatus[i];
}
}
return 0;
}
----------------------------------
V522 Dereferencing of the null pointer 'td' might take place. CommonCxxTests
testconditionvariable.cxx 96
VTK_THREAD_RETURN_TYPE vtkTestCondVarThread( void* arg )
{
...
if ( td )
{
...
}
else
{
cout << "No thread data!\n";
cout << " Thread " << ( threadId + 1 )
<< " of " << threadCount << " exiting.\n";
-- td->NumberOfWorkers; // dereferencing of the null pointer!
cout.flush();
}
...
}
----------------------------------
V523 The 'then' statement is equivalent to the 'else' statement. vtkRendering
vtkobjexporter.cxx 324
void vtkOBJExporter::WriteAnActor(....)
{
...
if (i%2)
{
i1 = i - 1;
i2 = i - 2;
}
else
{
i1 = i - 1;
i2 = i - 2;
}
...
}
----------------------------------
V528 It is odd that pointer to 'char' type is compared with the '\0' value.
Probably meant: *this->GeometryFileName == '\0'. vtkIO vtkbyureader.cxx 109
int vtkBYUReader::RequestData(....)
{
...
if (this->GeometryFileName == NULL ||
this->GeometryFileName == '\0')
...
}
----------------------------------
V530 The return value of function 'empty' is required to be utilized.
vtkRendering vtklabelhierarchy.cxx 425
std::vector<int> Path;
void vtkLabelHierarchyFrustumIterator::Next()
{
...
this->Path.empty();
...
}
Fix:
this->Path.clear();
----------------------------------
V535 The variable 'i' is being used for this loop and for the outer loop. vtkIO
vtklsdynareader.cxx 506
FillBlock(....)
{
...
for (vtkIdType i=0; i<p->Dict["NSURF"]; ++i)
{
...
for (vtkIdType t=0; t<segSz; ++t, ++currentCell)
{
...
for ( i=0; i<4; ++i )
{ ... }
...
}
...
}
...
}
Also:
V535 The variable 'i' is being used for this loop and for the outer loop.
vtklibxml2 xmlregexp.c 590
----------------------------------
V547 Expression is always true. Probably the '&&' operator should be used here.
vtkHybrid vtkmniobjectreader.cxx 161
int vtkMNIObjectReader::CanReadFile(const char* fname)
{
...
if (objType == 'P' || objType != 'L' ||
objType == 'M' || objType != 'F' ||
objType == 'X' || objType != 'Q' ||
objType == 'T')
...
}
----------------------------------
V547 Expression is always true. Probably the '&&' operator should be used here.
vtkIO vtknetcdfcfreader.cxx 838
int vtkNetCDFCFReader::RequestDataObject(....)
{
if ( (preferredDataType != VTK_IMAGE_DATA)
|| (preferredDataType != VTK_RECTILINEAR_GRID) )
{
vtkWarningMacro("You have set the OutputType to a data type that"
" cannot fully represent the topology of the data."
" Some of the topology will be ignored.");
}
}
Also:
V547 Expression is always true. Probably the '&&' operator should be used here.
vtkIO vtknetcdfcfreader.cxx 847
----------------------------------
V557 Array overrun is possible. The '6' index is pointing beyond array bound.
vtkGraphics vtkcursor2d.cxx 313
void vtkCursor2D::SetModelBounds(double bounds[6])
{
this->SetModelBounds(bounds[0], bounds[1], bounds[2],
bounds[3], bounds[6], bounds[5]);
}
----------------------------------
Also many V595. I have not studied it.
----------------------------------
Andrey Karpov,
Cand. Sc. (Physics and Mathematics), CTO
OOO "Program Verification Systems" (Co Ltd)
URL: www.viva64.com
E-Mail: karpov at viva64.com
======================================================================
Issue History
Date Modified Username Field Change
======================================================================
2012-08-24 04:29 Andrey New Issue
======================================================================
More information about the vtk-developers
mailing list