mirror of
https://gitlab.kitware.com/vtk/vtk-m
synced 2024-09-08 13:23:51 +00:00
Make sure return value of cell operations is initialized
Even if an error condition occurs, the output parameter should be initialized to something. This makes the behavior predicatable on error conditions and prevents uninitialized variable warnings.
This commit is contained in:
parent
51e817adc1
commit
0748725806
@ -42,6 +42,7 @@ VTKM_EXEC vtkm::ErrorCode CellDerivativeImpl(
|
||||
const ParametricCoordType& pcoords,
|
||||
vtkm::Vec<typename FieldVecType::ComponentType, 3>& result)
|
||||
{
|
||||
result = { 0 };
|
||||
if ((field.GetNumberOfComponents() != tag.numberOfPoints()) ||
|
||||
(wCoords.GetNumberOfComponents() != tag.numberOfPoints()))
|
||||
{
|
||||
@ -82,8 +83,9 @@ VTKM_EXEC vtkm::ErrorCode CellDerivative(const FieldVecType&,
|
||||
const WorldCoordType&,
|
||||
const vtkm::Vec<ParametricCoordType, 3>&,
|
||||
vtkm::CellShapeTagEmpty,
|
||||
vtkm::Vec<typename FieldVecType::ComponentType, 3>)
|
||||
vtkm::Vec<typename FieldVecType::ComponentType, 3>& result)
|
||||
{
|
||||
result = { 0 };
|
||||
return vtkm::ErrorCode::OperationOnEmptyCell;
|
||||
}
|
||||
|
||||
@ -97,6 +99,7 @@ VTKM_EXEC vtkm::ErrorCode CellDerivative(const FieldVecType& field,
|
||||
vtkm::IdComponent numPoints = field.GetNumberOfComponents();
|
||||
if (numPoints != wCoords.GetNumberOfComponents())
|
||||
{
|
||||
result = { 0 };
|
||||
return vtkm::ErrorCode::InvalidNumberOfPoints;
|
||||
}
|
||||
|
||||
@ -136,6 +139,7 @@ VTKM_EXEC vtkm::ErrorCode CellDerivative(const FieldVecType& field,
|
||||
const vtkm::IdComponent numPoints = field.GetNumberOfComponents();
|
||||
if ((numPoints <= 0) || (numPoints != wCoords.GetNumberOfComponents()))
|
||||
{
|
||||
result = { 0 };
|
||||
return vtkm::ErrorCode::InvalidNumberOfPoints;
|
||||
}
|
||||
|
||||
@ -186,14 +190,17 @@ VTKM_EXEC vtkm::ErrorCode CellDerivative(const FieldVecType& pointFieldValues,
|
||||
vtkm::CellShapeTagGeneric shape,
|
||||
vtkm::Vec<typename FieldVecType::ComponentType, 3>& result)
|
||||
{
|
||||
vtkm::ErrorCode status;
|
||||
switch (shape.Id)
|
||||
{
|
||||
vtkmGenericCellShapeMacro(return CellDerivative(
|
||||
pointFieldValues, worldCoordinateValues, parametricCoords, CellShapeTag(), result));
|
||||
vtkmGenericCellShapeMacro(
|
||||
status = CellDerivative(
|
||||
pointFieldValues, worldCoordinateValues, parametricCoords, CellShapeTag(), result));
|
||||
default:
|
||||
return vtkm::ErrorCode::InvalidShapeId;
|
||||
result = { 0 };
|
||||
status = vtkm::ErrorCode::InvalidShapeId;
|
||||
}
|
||||
return vtkm::ErrorCode::Success;
|
||||
return status;
|
||||
}
|
||||
|
||||
template <typename FieldVecType,
|
||||
|
@ -124,6 +124,7 @@ static inline VTKM_EXEC vtkm::ErrorCode CellEdgeNumberOfEdges(vtkm::IdComponent
|
||||
{
|
||||
if (numPoints != vtkm::CellTraits<CellShapeTag>::NUM_POINTS)
|
||||
{
|
||||
numEdges = -1;
|
||||
return vtkm::ErrorCode::InvalidNumberOfPoints;
|
||||
}
|
||||
numEdges = detail::CellEdgeTables{}.NumEdges(CellShapeTag::Id);
|
||||
@ -136,6 +137,7 @@ static inline VTKM_EXEC vtkm::ErrorCode CellEdgeNumberOfEdges(vtkm::IdComponent
|
||||
{
|
||||
if (numPoints <= 0)
|
||||
{
|
||||
numEdges = -1;
|
||||
return vtkm::ErrorCode::InvalidNumberOfPoints;
|
||||
}
|
||||
numEdges = numPoints;
|
||||
@ -148,6 +150,7 @@ static inline VTKM_EXEC vtkm::ErrorCode CellEdgeNumberOfEdges(vtkm::IdComponent
|
||||
{
|
||||
if (numPoints <= 0)
|
||||
{
|
||||
numEdges = -1;
|
||||
return vtkm::ErrorCode::InvalidNumberOfPoints;
|
||||
}
|
||||
numEdges = detail::CellEdgeTables{}.NumEdges(vtkm::CELL_SHAPE_POLY_LINE);
|
||||
@ -198,10 +201,12 @@ static inline VTKM_EXEC vtkm::ErrorCode CellEdgeLocalIndex(vtkm::IdComponent num
|
||||
{
|
||||
if ((pointIndex < 0) || (pointIndex > 1))
|
||||
{
|
||||
result = -1;
|
||||
return vtkm::ErrorCode::InvalidPointId;
|
||||
}
|
||||
if ((edgeIndex < 0) || (edgeIndex >= detail::CellEdgeTables::MAX_NUM_EDGES))
|
||||
{
|
||||
result = -1;
|
||||
return vtkm::ErrorCode::InvalidEdgeId;
|
||||
}
|
||||
|
||||
@ -209,6 +214,7 @@ static inline VTKM_EXEC vtkm::ErrorCode CellEdgeLocalIndex(vtkm::IdComponent num
|
||||
VTKM_RETURN_ON_ERROR(vtkm::exec::CellEdgeNumberOfEdges(numPoints, shape, numEdges));
|
||||
if (edgeIndex >= numEdges)
|
||||
{
|
||||
result = -1;
|
||||
return vtkm::ErrorCode::InvalidEdgeId;
|
||||
}
|
||||
|
||||
@ -225,14 +231,17 @@ static inline VTKM_EXEC vtkm::ErrorCode CellEdgeLocalIndex(vtkm::IdComponent num
|
||||
{
|
||||
if (numPoints < 3)
|
||||
{
|
||||
result = -1;
|
||||
return vtkm::ErrorCode::InvalidNumberOfPoints;
|
||||
}
|
||||
if ((pointIndex < 0) || (pointIndex > 1))
|
||||
{
|
||||
result = -1;
|
||||
return vtkm::ErrorCode::InvalidPointId;
|
||||
}
|
||||
if ((edgeIndex < 0) || (edgeIndex >= numPoints))
|
||||
{
|
||||
result = -1;
|
||||
return vtkm::ErrorCode::InvalidEdgeId;
|
||||
}
|
||||
|
||||
@ -255,10 +264,12 @@ static inline VTKM_EXEC vtkm::ErrorCode CellEdgeLocalIndex(vtkm::IdComponent num
|
||||
{
|
||||
if ((pointIndex < 0) || (pointIndex > 1))
|
||||
{
|
||||
result = -1;
|
||||
return vtkm::ErrorCode::InvalidPointId;
|
||||
}
|
||||
if ((edgeIndex < 0) || (edgeIndex >= detail::CellEdgeTables::MAX_NUM_EDGES))
|
||||
{
|
||||
result = -1;
|
||||
return vtkm::ErrorCode::InvalidEdgeId;
|
||||
}
|
||||
|
||||
@ -272,6 +283,7 @@ static inline VTKM_EXEC vtkm::ErrorCode CellEdgeLocalIndex(vtkm::IdComponent num
|
||||
detail::CellEdgeTables table;
|
||||
if (edgeIndex >= table.NumEdges(shape.Id))
|
||||
{
|
||||
result = -1;
|
||||
return vtkm::ErrorCode::InvalidEdgeId;
|
||||
}
|
||||
|
||||
@ -313,6 +325,8 @@ static inline VTKM_EXEC vtkm::ErrorCode CellEdgeCanonicalId(
|
||||
const GlobalPointIndicesVecType& globalPointIndicesVec,
|
||||
vtkm::Id2& result)
|
||||
{
|
||||
result = { -1, -1 };
|
||||
|
||||
vtkm::IdComponent localIndex0;
|
||||
VTKM_RETURN_ON_ERROR(vtkm::exec::CellEdgeLocalIndex(numPoints, 0, edgeIndex, shape, localIndex0));
|
||||
vtkm::Id pointIndex0 = globalPointIndicesVec[localIndex0];
|
||||
|
@ -172,6 +172,7 @@ static inline VTKM_EXEC vtkm::ErrorCode CellFaceNumberOfPoints(vtkm::IdComponent
|
||||
{
|
||||
if ((faceIndex < 0) || (faceIndex >= detail::CellFaceTables::MAX_NUM_FACES))
|
||||
{
|
||||
result = -1;
|
||||
return vtkm::ErrorCode::InvalidFaceId;
|
||||
}
|
||||
|
||||
@ -179,6 +180,7 @@ static inline VTKM_EXEC vtkm::ErrorCode CellFaceNumberOfPoints(vtkm::IdComponent
|
||||
VTKM_RETURN_ON_ERROR(vtkm::exec::CellFaceNumberOfFaces(shape, numFaces));
|
||||
if (faceIndex >= numFaces)
|
||||
{
|
||||
result = -1;
|
||||
return vtkm::ErrorCode::InvalidFaceId;
|
||||
}
|
||||
detail::CellFaceTables table;
|
||||
@ -210,6 +212,7 @@ static inline VTKM_EXEC vtkm::ErrorCode CellFaceShape(vtkm::IdComponent faceInde
|
||||
|
||||
if ((faceIndex < 0) || (faceIndex >= detail::CellFaceTables::MAX_NUM_FACES))
|
||||
{
|
||||
result = vtkm::CELL_SHAPE_EMPTY;
|
||||
return vtkm::ErrorCode::InvalidFaceId;
|
||||
}
|
||||
|
||||
@ -252,6 +255,7 @@ static inline VTKM_EXEC vtkm::ErrorCode CellFaceLocalIndex(vtkm::IdComponent poi
|
||||
vtkm::IdComponent& result)
|
||||
{
|
||||
vtkm::IdComponent numPointsInFace;
|
||||
result = -1;
|
||||
VTKM_RETURN_ON_ERROR(vtkm::exec::CellFaceNumberOfPoints(faceIndex, shape, numPointsInFace));
|
||||
if (numPointsInFace < 1)
|
||||
{
|
||||
@ -300,6 +304,7 @@ static inline VTKM_EXEC vtkm::ErrorCode CellFaceCanonicalId(
|
||||
vtkm::Id3& result)
|
||||
{
|
||||
vtkm::IdComponent numPointsInFace;
|
||||
result = { -1 };
|
||||
VTKM_RETURN_ON_ERROR(vtkm::exec::CellFaceNumberOfPoints(faceIndex, shape, numPointsInFace));
|
||||
if (numPointsInFace == 0)
|
||||
{
|
||||
|
@ -40,6 +40,7 @@ VTKM_EXEC vtkm::ErrorCode CellInterpolateImpl(VtkcCellShapeTag tag,
|
||||
{
|
||||
if (tag.numberOfPoints() != field.GetNumberOfComponents())
|
||||
{
|
||||
result = { 0 };
|
||||
return vtkm::ErrorCode::InvalidNumberOfPoints;
|
||||
}
|
||||
|
||||
@ -68,8 +69,9 @@ template <typename FieldVecType, typename ParametricCoordType>
|
||||
VTKM_EXEC vtkm::ErrorCode CellInterpolate(const FieldVecType&,
|
||||
const vtkm::Vec<ParametricCoordType, 3>&,
|
||||
vtkm::CellShapeTagEmpty,
|
||||
typename FieldVecType::ComponentType&)
|
||||
typename FieldVecType::ComponentType& result)
|
||||
{
|
||||
result = { 0 };
|
||||
return vtkm::ErrorCode::OperationOnEmptyCell;
|
||||
}
|
||||
|
||||
@ -83,6 +85,7 @@ VTKM_EXEC vtkm::ErrorCode CellInterpolate(const FieldVecType& field,
|
||||
const vtkm::IdComponent numPoints = field.GetNumberOfComponents();
|
||||
if (numPoints < 1)
|
||||
{
|
||||
result = { 0 };
|
||||
return vtkm::ErrorCode::InvalidNumberOfPoints;
|
||||
}
|
||||
|
||||
@ -116,6 +119,7 @@ VTKM_EXEC vtkm::ErrorCode CellInterpolate(const FieldVecType& field,
|
||||
const vtkm::IdComponent numPoints = field.GetNumberOfComponents();
|
||||
if (numPoints < 1)
|
||||
{
|
||||
result = { 0 };
|
||||
return vtkm::ErrorCode::InvalidNumberOfPoints;
|
||||
}
|
||||
|
||||
@ -162,13 +166,16 @@ VTKM_EXEC vtkm::ErrorCode CellInterpolate(const FieldVecType& pointFieldValues,
|
||||
vtkm::CellShapeTagGeneric shape,
|
||||
typename FieldVecType::ComponentType& result)
|
||||
{
|
||||
vtkm::ErrorCode status;
|
||||
switch (shape.Id)
|
||||
{
|
||||
vtkmGenericCellShapeMacro(
|
||||
return CellInterpolate(pointFieldValues, parametricCoords, CellShapeTag(), result));
|
||||
status = CellInterpolate(pointFieldValues, parametricCoords, CellShapeTag(), result));
|
||||
default:
|
||||
return vtkm::ErrorCode::InvalidShapeId;
|
||||
result = { 0 };
|
||||
status = vtkm::ErrorCode::InvalidShapeId;
|
||||
}
|
||||
return status;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
@ -98,6 +98,7 @@ static inline VTKM_EXEC vtkm::ErrorCode ParametricCoordinatesCenter(
|
||||
{
|
||||
if (numPoints < 1)
|
||||
{
|
||||
pcoords = { 0 };
|
||||
return vtkm::ErrorCode::InvalidNumberOfPoints;
|
||||
}
|
||||
switch (numPoints)
|
||||
@ -123,13 +124,16 @@ static inline VTKM_EXEC vtkm::ErrorCode ParametricCoordinatesCenter(
|
||||
vtkm::CellShapeTagGeneric shape,
|
||||
vtkm::Vec<ParametricCoordType, 3>& pcoords)
|
||||
{
|
||||
vtkm::ErrorCode status;
|
||||
switch (shape.Id)
|
||||
{
|
||||
vtkmGenericCellShapeMacro(
|
||||
return ParametricCoordinatesCenter(numPoints, CellShapeTag(), pcoords));
|
||||
vtkmGenericCellShapeMacro(status =
|
||||
ParametricCoordinatesCenter(numPoints, CellShapeTag(), pcoords));
|
||||
default:
|
||||
return vtkm::ErrorCode::InvalidShapeId;
|
||||
pcoords = { 0 };
|
||||
status = vtkm::ErrorCode::InvalidShapeId;
|
||||
}
|
||||
return status;
|
||||
}
|
||||
|
||||
template <typename ParametricCoordType, typename CellShapeTag>
|
||||
@ -177,10 +181,12 @@ static inline VTKM_EXEC vtkm::ErrorCode ParametricCoordinatesPoint(
|
||||
|
||||
if (numPoints != lclTag.numberOfPoints())
|
||||
{
|
||||
pcoords = { 0 };
|
||||
return vtkm::ErrorCode::InvalidNumberOfPoints;
|
||||
}
|
||||
if ((pointIndex < 0) || (pointIndex >= numPoints))
|
||||
{
|
||||
pcoords = { 0 };
|
||||
return vtkm::ErrorCode::InvalidPointId;
|
||||
}
|
||||
|
||||
@ -227,6 +233,7 @@ static inline VTKM_EXEC vtkm::ErrorCode ParametricCoordinatesPoint(
|
||||
{
|
||||
if (numPoints < 1)
|
||||
{
|
||||
pcoords = { 0 };
|
||||
return vtkm::ErrorCode::InvalidNumberOfPoints;
|
||||
}
|
||||
switch (numPoints)
|
||||
@ -274,14 +281,16 @@ static inline VTKM_EXEC vtkm::ErrorCode ParametricCoordinatesPoint(
|
||||
vtkm::CellShapeTagGeneric shape,
|
||||
vtkm::Vec<ParametricCoordType, 3>& pcoords)
|
||||
{
|
||||
vtkm::ErrorCode status;
|
||||
switch (shape.Id)
|
||||
{
|
||||
vtkmGenericCellShapeMacro(
|
||||
return ParametricCoordinatesPoint(numPoints, pointIndex, CellShapeTag(), pcoords));
|
||||
status = ParametricCoordinatesPoint(numPoints, pointIndex, CellShapeTag(), pcoords));
|
||||
default:
|
||||
pcoords[0] = pcoords[1] = pcoords[2] = 0;
|
||||
return vtkm::ErrorCode::InvalidShapeId;
|
||||
status = vtkm::ErrorCode::InvalidShapeId;
|
||||
}
|
||||
return status;
|
||||
}
|
||||
|
||||
template <typename ParametricCoordType, typename CellShapeTag>
|
||||
@ -426,13 +435,16 @@ static inline VTKM_EXEC vtkm::ErrorCode ParametricCoordinatesToWorldCoordinates(
|
||||
vtkm::CellShapeTagGeneric shape,
|
||||
typename WorldCoordVector::ComponentType& result)
|
||||
{
|
||||
vtkm::ErrorCode status;
|
||||
switch (shape.Id)
|
||||
{
|
||||
vtkmGenericCellShapeMacro(return ParametricCoordinatesToWorldCoordinates(
|
||||
pointWCoords, pcoords, CellShapeTag(), result));
|
||||
vtkmGenericCellShapeMacro(status = ParametricCoordinatesToWorldCoordinates(
|
||||
pointWCoords, pcoords, CellShapeTag(), result));
|
||||
default:
|
||||
return vtkm::ErrorCode::InvalidShapeId;
|
||||
result = { 0 };
|
||||
status = vtkm::ErrorCode::InvalidShapeId;
|
||||
}
|
||||
return status;
|
||||
}
|
||||
|
||||
template <typename WorldCoordVector, typename PCoordType, typename CellShapeTag>
|
||||
@ -468,6 +480,7 @@ static inline VTKM_EXEC vtkm::ErrorCode WorldCoordinatesToParametricCoordinatesI
|
||||
{
|
||||
if (pointWCoords.GetNumberOfComponents() != tag.numberOfPoints())
|
||||
{
|
||||
result = { 0 };
|
||||
return vtkm::ErrorCode::InvalidNumberOfPoints;
|
||||
}
|
||||
|
||||
@ -495,8 +508,9 @@ static inline VTKM_EXEC vtkm::ErrorCode WorldCoordinatesToParametricCoordinates(
|
||||
const WorldCoordVector&,
|
||||
const typename WorldCoordVector::ComponentType&,
|
||||
vtkm::CellShapeTagEmpty,
|
||||
typename WorldCoordVector::ComponentType&)
|
||||
typename WorldCoordVector::ComponentType& result)
|
||||
{
|
||||
result = { 0 };
|
||||
return vtkm::ErrorCode::OperationOnEmptyCell;
|
||||
}
|
||||
|
||||
@ -509,6 +523,7 @@ static inline VTKM_EXEC vtkm::ErrorCode WorldCoordinatesToParametricCoordinates(
|
||||
{
|
||||
if (pointWCoords.GetNumberOfComponents() != 1)
|
||||
{
|
||||
result = { 0 };
|
||||
return vtkm::ErrorCode::InvalidNumberOfPoints;
|
||||
}
|
||||
result = typename WorldCoordVector::ComponentType(0, 0, 0);
|
||||
@ -525,6 +540,7 @@ static inline VTKM_EXEC vtkm::ErrorCode WorldCoordinatesToParametricCoordinates(
|
||||
vtkm::IdComponent numPoints = pointWCoords.GetNumberOfComponents();
|
||||
if (numPoints < 1)
|
||||
{
|
||||
result = { 0 };
|
||||
return vtkm::ErrorCode::InvalidNumberOfPoints;
|
||||
}
|
||||
|
||||
@ -626,13 +642,16 @@ static inline VTKM_EXEC vtkm::ErrorCode WorldCoordinatesToParametricCoordinates(
|
||||
vtkm::CellShapeTagGeneric shape,
|
||||
typename WorldCoordVector::ComponentType& result)
|
||||
{
|
||||
vtkm::ErrorCode status;
|
||||
switch (shape.Id)
|
||||
{
|
||||
vtkmGenericCellShapeMacro(return WorldCoordinatesToParametricCoordinates(
|
||||
pointWCoords, wcoords, CellShapeTag(), result));
|
||||
vtkmGenericCellShapeMacro(status = WorldCoordinatesToParametricCoordinates(
|
||||
pointWCoords, wcoords, CellShapeTag(), result));
|
||||
default:
|
||||
return vtkm::ErrorCode::InvalidShapeId;
|
||||
result = { 0 };
|
||||
status = vtkm::ErrorCode::InvalidShapeId;
|
||||
}
|
||||
return status;
|
||||
}
|
||||
|
||||
template <typename WorldCoordVector, typename CellShapeTag>
|
||||
|
@ -300,8 +300,17 @@ struct ExternalFaces
|
||||
for (vtkm::IdComponent facePointIndex = 0; facePointIndex < numFacePoints; facePointIndex++)
|
||||
{
|
||||
vtkm::IdComponent localFaceIndex;
|
||||
vtkm::exec::CellFaceLocalIndex(facePointIndex, faceIndex, shape, localFaceIndex);
|
||||
faceConnectivity[facePointIndex] = inCellIndices[localFaceIndex];
|
||||
vtkm::ErrorCode status =
|
||||
vtkm::exec::CellFaceLocalIndex(facePointIndex, faceIndex, shape, localFaceIndex);
|
||||
if (status == vtkm::ErrorCode::Success)
|
||||
{
|
||||
faceConnectivity[facePointIndex] = inCellIndices[localFaceIndex];
|
||||
}
|
||||
else
|
||||
{
|
||||
// An error condition, but do we want to crash the operation?
|
||||
faceConnectivity[facePointIndex] = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -559,8 +568,17 @@ public:
|
||||
for (vtkm::IdComponent facePointIndex = 0; facePointIndex < numFacePoints; facePointIndex++)
|
||||
{
|
||||
vtkm::IdComponent localFaceIndex;
|
||||
vtkm::exec::CellFaceLocalIndex(facePointIndex, myFace, shapeIn, localFaceIndex);
|
||||
connectivityOut[facePointIndex] = inCellIndices[localFaceIndex];
|
||||
vtkm::ErrorCode status =
|
||||
vtkm::exec::CellFaceLocalIndex(facePointIndex, myFace, shapeIn, localFaceIndex);
|
||||
if (status == vtkm::ErrorCode::Success)
|
||||
{
|
||||
connectivityOut[facePointIndex] = inCellIndices[localFaceIndex];
|
||||
}
|
||||
else
|
||||
{
|
||||
// An error condition, but do we want to crash the operation?
|
||||
connectivityOut[facePointIndex] = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user