From 239ffce850261f2790f624e3a45f264544274bcc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Offringa?= Date: Wed, 16 Oct 2019 21:05:54 +0200 Subject: [PATCH] Fix dry mode crash when having deep dir structure (#221) Deep dir structures would cause followDown() to incorrectly return nullptr. --- tests/testfolder.cpp | 17 +++++++++++++++++ theatre/folder.h | 4 ++-- 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/tests/testfolder.cpp b/tests/testfolder.cpp index 3c058460..84c17ea2 100644 --- a/tests/testfolder.cpp +++ b/tests/testfolder.cpp @@ -123,6 +123,23 @@ BOOST_AUTO_TEST_CASE( FollowDown ) BOOST_CHECK_EQUAL( a->FollowDown("b/c") , c.get() ); BOOST_CHECK_EQUAL( b->FollowDown("c") , c.get() ); + + std::unique_ptr root(new Folder("root")); + std::unique_ptr f1(new Folder("bert")); + std::unique_ptr f2(new Folder("carole")); + std::unique_ptr f3(new Folder("daniel")); + f2->Add(*f3); + f1->Add(*f2); + root->Add(*f1); + BOOST_CHECK_EQUAL( + root->FollowDown(Folder::RemoveRoot("root/bert/carole/daniel")), + f3.get() + ); + std::string notMoved = Folder::RemoveRoot("root/bert/carole/daniel"); + BOOST_CHECK_EQUAL( + root->FollowDown(notMoved), + f3.get() + ); } diff --git a/theatre/folder.h b/theatre/folder.h index 5d5b5302..8769acf9 100644 --- a/theatre/folder.h +++ b/theatre/folder.h @@ -239,7 +239,7 @@ class Folder : public FolderObject return dynamic_cast(obj); } else { - FolderObject* obj = FindNamedObjectIfExists(_objects, path.substr(strPos, sep-path.begin())); + FolderObject* obj = FindNamedObjectIfExists(_objects, path.substr(strPos, sep-path.begin()-strPos)); Folder* folder = dynamic_cast(obj); if(folder) return folder->followDown(path, sep+1-path.begin()); @@ -258,7 +258,7 @@ class Folder : public FolderObject return dynamic_cast(obj); } else { - FolderObject* obj = FindNamedObjectIfExists(_objects, path.substr(strPos, sep-path.begin())); + FolderObject* obj = FindNamedObjectIfExists(_objects, path.substr(strPos, sep-path.begin()-strPos)); Folder* folder = dynamic_cast(obj); if(folder) return folder->followDown(std::move(path), sep+1-path.begin());