Fixes crashes when using bad smiles in the cached smiles holders (#3798)

* Fixes #3797

* Update Code/GraphMol/SubstructLibrary/SubstructLibrary.cpp

Co-authored-by: Greg Landrum <greg.landrum@gmail.com>

* Update test to include positive and negative results

Co-authored-by: Greg Landrum <greg.landrum@gmail.com>
This commit is contained in:
Brian Kelley
2021-02-15 04:49:19 -05:00
committed by greg landrum
parent 8e6a96e392
commit 9100096102
4 changed files with 47 additions and 4 deletions

View File

@@ -458,6 +458,36 @@ void testAddPatterns() {
}
void testSegFaultInHolder() {
BOOST_LOG(rdErrorLog) << "-------------------------------------" << std::endl;
BOOST_LOG(rdErrorLog) << " testSegFaultInHolder" << std::endl;
boost::shared_ptr<CachedTrustedSmilesMolHolder> mols1(
new CachedTrustedSmilesMolHolder());
boost::shared_ptr<CachedSmilesMolHolder> mols2(
new CachedSmilesMolHolder());
for(int i=0; i<100; ++i) {
if(i%2==0) {
mols1->addSmiles("dsafsdf");
mols2->addSmiles("dsafsdf");
} else {
mols1->addSmiles("c1ccccc1");
mols2->addSmiles("c1ccccc1");
}
}
SubstructLibrary sss(mols1);
SubstructLibrary sss2(mols2);
ROMOL_SPTR query(SmartsToMol("c1ccccc1"));
auto matches1 = sss.getMatches(*query);
TEST_ASSERT(matches1.size() == 50);
matches1 = sss2.getMatches(*query);
TEST_ASSERT(matches1.size() == 50);
// Check that we don't segfault when adding patterns
addPatterns(sss, 2);
addPatterns(sss2, 2);
}
int main() {
@@ -470,6 +500,7 @@ int main() {
docTest();
ringTest();
testAddPatterns();
testSegFaultInHolder();
#endif
return 0;
}