From 6b1d4a4f08a45201ed42147fe9c22619f02fd2be Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Mon, 6 Jan 2020 19:54:32 +0100 Subject: [PATCH] MeshTools: regression test for an OOB access in tipsify(). That was harder than I thought. --- src/Magnum/MeshTools/Test/TipsifyTest.cpp | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/Magnum/MeshTools/Test/TipsifyTest.cpp b/src/Magnum/MeshTools/Test/TipsifyTest.cpp index 92ca9411d..3b7e97299 100644 --- a/src/Magnum/MeshTools/Test/TipsifyTest.cpp +++ b/src/Magnum/MeshTools/Test/TipsifyTest.cpp @@ -36,6 +36,7 @@ struct TipsifyTest: TestSuite::Tester { void buildAdjacency(); void tipsify(); + void oneDegenerateTriangle(); }; /* @@ -82,7 +83,8 @@ constexpr std::size_t VertexCount = 19; TipsifyTest::TipsifyTest() { addTests({&TipsifyTest::buildAdjacency, - &TipsifyTest::tipsify}); + &TipsifyTest::tipsify, + &TipsifyTest::oneDegenerateTriangle}); } void TipsifyTest::buildAdjacency() { @@ -158,6 +160,15 @@ void TipsifyTest::tipsify() { })); } +void TipsifyTest::oneDegenerateTriangle() { + /* There used to be an OOB access (neighbors[++ti]) caught by ASan, this + triggers it */ + std::vector indices{0, 0, 0}; + MeshTools::tipsify(indices, 1, 2); + + CORRADE_COMPARE(indices, (std::vector{0, 0, 0})); +} + }}}} CORRADE_TEST_MAIN(Magnum::MeshTools::Test::TipsifyTest)