Skip to content

Commit

Permalink
Fix dry mode crash when having deep dir structure (#221)
Browse files Browse the repository at this point in the history
Deep dir structures would cause followDown() to incorrectly return nullptr.
  • Loading branch information
aroffringa authored Oct 16, 2019
1 parent 63871e2 commit 239ffce
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
17 changes: 17 additions & 0 deletions tests/testfolder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<Folder> root(new Folder("root"));
std::unique_ptr<Folder> f1(new Folder("bert"));
std::unique_ptr<Folder> f2(new Folder("carole"));
std::unique_ptr<Folder> 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()
);
}


Expand Down
4 changes: 2 additions & 2 deletions theatre/folder.h
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ class Folder : public FolderObject
return dynamic_cast<Folder*>(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<Folder*>(obj);
if(folder)
return folder->followDown(path, sep+1-path.begin());
Expand All @@ -258,7 +258,7 @@ class Folder : public FolderObject
return dynamic_cast<Folder*>(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<Folder*>(obj);
if(folder)
return folder->followDown(std::move(path), sep+1-path.begin());
Expand Down

0 comments on commit 239ffce

Please sign in to comment.