diff --git a/src/cltools/Driver.cpp b/src/cltools/Driver.cpp index b826c3b1fc..1becea88a5 100644 --- a/src/cltools/Driver.cpp +++ b/src/cltools/Driver.cpp @@ -727,7 +727,9 @@ int Driver::main(FILE* in,FILE*out,Communicator& pc) { std::map > data; IFile ifile; ifile.open(plumedFile); std::vector words; while( Tools::getParsedLine(ifile,words) && !p.getEndPlumed() ) { - p.readInputWords(words,false); Action* aa=p.getActionSet()[p.getActionSet().size()-1].get(); + p.readInputWords(words,false); + Action* aa=p.getActionSet()[p.getActionSet().size()-1].get(); + plumed_assert(aa); // needed for following calls, see #1046 ActionWithValue* av=aa->castToActionWithValue(); if( av && aa->getDefaultString().length()>0 ) { std::vector def; def.push_back( "defaults " + aa->getDefaultString() ); diff --git a/src/core/ActionAtomistic.cpp b/src/core/ActionAtomistic.cpp index f4d268bb94..c0de85bd7c 100644 --- a/src/core/ActionAtomistic.cpp +++ b/src/core/ActionAtomistic.cpp @@ -53,6 +53,7 @@ ActionAtomistic::ActionAtomistic(const ActionOptions&ao): // We now get all the information about atoms that are lying about std::vector vatoms = plumed.getActionSet().select(); for(const auto & vv : vatoms ) { + plumed_assert(vv); // needed for following calls, see #1046 ActionToPutData* ap = vv->castToActionToPutData(); if( ap ) { if( ap->getRole()=="x" ) xpos.push_back( ap->copyOutput(0) ); @@ -324,11 +325,15 @@ std::pair ActionAtomistic::getValueIndices( const Atom void ActionAtomistic::retrieveAtoms( const bool& force ) { if( boxValue ) { - PbcAction* pbca = boxValue->getPntrToAction()->castToPbcAction(); + auto* ptr=boxValue->getPntrToAction(); + plumed_assert(ptr); // needed for following calls, see #1046 + PbcAction* pbca = ptr->castToPbcAction(); plumed_assert( pbca ); pbc=pbca->pbc; } if( donotretrieve || indexes.size()==0 ) return; - ActionToPutData* cv = chargev[0]->getPntrToAction()->castToActionToPutData(); + auto * ptr=chargev[0]->getPntrToAction(); + plumed_assert(ptr); // needed for following calls, see #1046 + ActionToPutData* cv = ptr->castToActionToPutData(); if(cv) chargesWereSet=cv->hasBeenSet(); unsigned j = 0; diff --git a/src/core/ActionToPutData.cpp b/src/core/ActionToPutData.cpp index 06988487f0..ad9648b734 100644 --- a/src/core/ActionToPutData.cpp +++ b/src/core/ActionToPutData.cpp @@ -160,7 +160,9 @@ void ActionToPutData::apply() { unsigned ActionToPutData::getNumberOfForcesToRescale() const { if( getName()!="ENERGY" || getDependencies().size()>0 ) return copyOutput(0)->getNumberOfValues(); - plumed_assert( getDependencies().size()==1 ); ActionForInterface* ai = getDependencies()[0]->castToActionForInterface(); + plumed_assert( getDependencies().size()==1 ); + plumed_assert(getDependencies()[0]); // needed for following calls, see #1046 + ActionForInterface* ai = getDependencies()[0]->castToActionForInterface(); return ai->getNumberOfForcesToRescale(); } diff --git a/src/core/ActionWithArguments.cpp b/src/core/ActionWithArguments.cpp index d35f7f9047..8e84498f9a 100644 --- a/src/core/ActionWithArguments.cpp +++ b/src/core/ActionWithArguments.cpp @@ -107,6 +107,7 @@ void ActionWithArguments::interpretArgumentList(const std::vector& std::vector all=as.select(); if( all.empty() ) readact->error("your input file is not telling plumed to calculate anything"); for(unsigned j=0; jcastToActionForInterface(); if( ap ) continue; for(int k=0; kgetNumberOfComponents(); ++k) arg.push_back(all[j]->copyOutput(k)); } @@ -166,6 +167,7 @@ void ActionWithArguments::interpretArgumentList(const std::vector& std::vector all=as.select(); if( all.empty() ) readact->error("your input file is not telling plumed to calculate anything"); for(unsigned j=0; jcastToActionWithVirtualAtom(); if( av ) continue; ActionForInterface* ap=all[j]->castToActionForInterface(); if( ap && all[j]->getName()!="ENERGY" ) continue; for(int k=0; kgetNumberOfComponents(); ++k) arg.push_back(all[j]->copyOutput(k)); @@ -327,7 +329,9 @@ bool ActionWithArguments::calculateConstantValues( const bool& haveatoms ) { if( !av || arguments.size()==0 ) return false; bool constant = true, atoms=false; for(unsigned i=0; igetPntrToAction()->castToActionAtomistic(); + auto * ptr=arguments[i]->getPntrToAction(); + plumed_assert(ptr); // needed for following calls, see #1046 + ActionAtomistic* aa=ptr->castToActionAtomistic(); if( aa ) { ActionWithVector* av=dynamic_cast( arguments[i]->getPntrToAction() ); if( !av || aa->getNumberOfAtoms()>0 ) atoms=true; diff --git a/src/core/PlumedMain.cpp b/src/core/PlumedMain.cpp index c7c87540fc..63a78c2189 100644 --- a/src/core/PlumedMain.cpp +++ b/src/core/PlumedMain.cpp @@ -434,6 +434,7 @@ void PlumedMain::cmd(std::string_view word,const TypesafePtr & val) { CHECK_INIT(initialized,word); CHECK_NOTNULL(val,word); for(const auto & pp : inputs ) { + plumed_assert(pp); DomainDecomposition* dd=pp->castToDomainDecomposition(); if( dd ) dd->setAtomsNlocal(val.get()); } @@ -441,6 +442,7 @@ void PlumedMain::cmd(std::string_view word,const TypesafePtr & val) { case cmd_setAtomsGatindex: CHECK_INIT(initialized,word); for(const auto & pp : inputs ) { + plumed_assert(pp); DomainDecomposition* dd=pp->castToDomainDecomposition(); if( dd ) dd->setAtomsGatindex(val,false); } @@ -448,6 +450,7 @@ void PlumedMain::cmd(std::string_view word,const TypesafePtr & val) { case cmd_setAtomsFGatindex: CHECK_INIT(initialized,word); for(const auto & pp : inputs ) { + plumed_assert(pp); DomainDecomposition* dd=pp->castToDomainDecomposition(); if( dd ) dd->setAtomsGatindex(val,false); } @@ -456,6 +459,7 @@ void PlumedMain::cmd(std::string_view word,const TypesafePtr & val) { CHECK_INIT(initialized,word); CHECK_NOTNULL(val,word); for(const auto & pp : inputs ) { + plumed_assert(pp); DomainDecomposition* dd=pp->castToDomainDecomposition(); if( dd ) dd->setAtomsContiguous(val.get()); } @@ -464,6 +468,7 @@ void PlumedMain::cmd(std::string_view word,const TypesafePtr & val) { CHECK_INIT(initialized,word); CHECK_NOTNULL(val,word); for(const auto & pp : inputs ) { + plumed_assert(pp); DomainDecomposition* dd=pp->castToDomainDecomposition(); if( dd ) dd->createFullList(val); } @@ -474,6 +479,7 @@ void PlumedMain::cmd(std::string_view word,const TypesafePtr & val) { CHECK_NOTNULL(val,word); unsigned nlists=0; for(const auto & pp : inputs ) { + plumed_assert(pp); DomainDecomposition* dd=pp->castToDomainDecomposition(); if( dd ) { dd->getFullList(val); nlists++; } } @@ -483,6 +489,7 @@ void PlumedMain::cmd(std::string_view word,const TypesafePtr & val) { case cmd_clearFullList: CHECK_INIT(initialized,word); for(const auto & pp : inputs ) { + plumed_assert(pp); DomainDecomposition* dd=pp->castToDomainDecomposition(); if( dd ) dd->clearFullList(); } @@ -540,6 +547,7 @@ void PlumedMain::cmd(std::string_view word,const TypesafePtr & val) { CHECK_INIT(initialized,word); std::vector natoms; for(const auto & pp : inputs ) { + plumed_assert(pp); DomainDecomposition* dd=pp->castToDomainDecomposition(); if ( dd ) natoms.push_back( dd->getNumberOfAtoms() ); } @@ -873,6 +881,7 @@ void PlumedMain::init() { log<<"Number of threads: "<castToDomainDecomposition(); if ( dd ) log.printf("Number of atoms: %d\n",dd->getNumberOfAtoms()); } @@ -1123,6 +1132,7 @@ void PlumedMain::justCalculate() { // calculate the active actions in order (assuming *backward* dependence) for(const auto & pp : actionSet) { Action* p(pp.get()); + plumed_assert(p); try { if(p->isActive()) { // Stopwatch is stopped when sw goes out of scope.