From bbdfd3d52b2a4e38062d13705ec6fd02f98c0b8e Mon Sep 17 00:00:00 2001 From: Kenneth Moreland Date: Fri, 5 Aug 2022 12:55:45 -0600 Subject: [PATCH] Do not assume that LastCell initializes to -1 If an `ArrayHandle` of `LastCell`s is created, then the contents will be garbage. Just check to make sure that it is valid. --- vtkm/exec/CellLocatorBoundingIntervalHierarchy.h | 4 ++-- vtkm/exec/CellLocatorTwoLevel.h | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/vtkm/exec/CellLocatorBoundingIntervalHierarchy.h b/vtkm/exec/CellLocatorBoundingIntervalHierarchy.h index c314f18d8..620c7754d 100644 --- a/vtkm/exec/CellLocatorBoundingIntervalHierarchy.h +++ b/vtkm/exec/CellLocatorBoundingIntervalHierarchy.h @@ -107,7 +107,7 @@ public: cellId = -1; //Check the last cell. - if (lastCell.CellId != -1) + if ((lastCell.CellId >= 0) && (lastCell.CellId < this->CellSet.GetNumberOfElements())) { if (this->PointInCell(point, lastCell.CellId, parametric) == vtkm::ErrorCode::Success) { @@ -117,7 +117,7 @@ public: } //Check the last leaf node. - if (lastCell.NodeIdx != -1) + if ((lastCell.NodeIdx >= 0) && (lastCell.NodeIdx < this->Nodes.GetNumberOfValues())) { const auto& node = this->Nodes.Get(lastCell.NodeIdx); VTKM_ASSERT(node.ChildIndex < 0); //should be a leaf node. diff --git a/vtkm/exec/CellLocatorTwoLevel.h b/vtkm/exec/CellLocatorTwoLevel.h index cafafaaba..d432c98f7 100644 --- a/vtkm/exec/CellLocatorTwoLevel.h +++ b/vtkm/exec/CellLocatorTwoLevel.h @@ -174,7 +174,7 @@ public: { vtkm::Vec3f pc; //See if point is inside the last cell. - if (lastCell.CellId != -1 && + if ((lastCell.CellId >= 0) && (lastCell.CellId < this->CellSet.GetNumberOfElements()) && this->PointInCell(point, lastCell.CellId, pc) == vtkm::ErrorCode::Success) { parametric = pc; @@ -183,7 +183,7 @@ public: } //See if it's in the last leaf. - if (lastCell.LeafIdx != -1 && + if ((lastCell.LeafIdx >= 0) && (lastCell.LeafIdx < this->CellCount.GetNumberOfValues()) && this->PointInLeaf(point, lastCell.LeafIdx, cellId, pc) == vtkm::ErrorCode::Success) { parametric = pc;