From 89a2b571cfc0ea87c26ba8b1ed1ab87d13244f0e Mon Sep 17 00:00:00 2001 From: Michele Di Giorgio Date: Fri, 29 Jun 2018 11:17:18 +0100 Subject: COMPMID-1351: Valgrind: CannyEdge out of bound access in reference / trace_edge function Change-Id: I8bb9beabf86d84576335b8b8c064045c7573b342 Reviewed-on: https://eu-gerrit-1.euhpc.arm.com/137987 Tested-by: Jenkins Reviewed-by: Georgios Pinitas --- tests/validation/reference/CannyEdgeDetector.cpp | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/tests/validation/reference/CannyEdgeDetector.cpp b/tests/validation/reference/CannyEdgeDetector.cpp index 6fe4544cf6..f1ad98cb3b 100644 --- a/tests/validation/reference/CannyEdgeDetector.cpp +++ b/tests/validation/reference/CannyEdgeDetector.cpp @@ -50,7 +50,7 @@ const auto MARK_MAYBE = 127u; const auto MARK_EDGE = 255u; template -void trace_edge(SimpleTensor &dst) +void trace_edge(SimpleTensor &dst, const ValidRegion &valid_region) { std::stack pixels_stack; for(auto i = 0; i < dst.num_elements(); ++i) @@ -83,12 +83,15 @@ void trace_edge(SimpleTensor &dst) // Mark MAYBE neighbours as edges since they are next to an EDGE std::for_each(neighbours.begin(), neighbours.end(), [&](Coordinates & coord) { - const size_t pixel_index = coord2index(dst.shape(), coord); - const T pixel = dst[pixel_index]; - if(pixel == MARK_MAYBE) + if(is_in_valid_region(valid_region, coord)) { - dst[pixel_index] = MARK_EDGE; - pixels_stack.push(coord); + const size_t pixel_index = coord2index(dst.shape(), coord); + const T pixel = dst[pixel_index]; + if(pixel == MARK_MAYBE) + { + dst[pixel_index] = MARK_EDGE; + pixels_stack.push(coord); + } } }); } @@ -221,7 +224,7 @@ SimpleTensor canny_edge_detector_impl(const SimpleTensor &src, int32_t upp } // Final edge tracing - trace_edge(dst); + trace_edge(dst, valid_region); return dst; } } // namespace -- cgit v1.2.1