Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ostream operator can easily enter infinite loop #105

Closed
tmadlener opened this issue Jun 24, 2020 · 0 comments · Fixed by #106
Closed

ostream operator can easily enter infinite loop #105

tmadlener opened this issue Jun 24, 2020 · 0 comments · Fixed by #106

Comments

@tmadlener
Copy link
Collaborator

It is easily possible to enter an infinite loop (and a subsequent core dump) using the ostream operator if OneToManyRelations are used like they are e.g. in ExampleMC (only the important parts here):

ExampleMC:
  OneToManyRelations:
    - ExampleMC parents
    - ExampleMC daughters

Properly setting mother/daughter relations in this case

ExampleMC mcp1;
ExampleMC mcp2;

mcp1.adddaughters(mcp2);
mcp2.adddaughters(mcp1);

will lead to an infinite loop in the ostream operator, since that is generated to be

std::ostream& operator<<( std::ostream& o,const ConstExampleMC& value ){
  o << " id : " << value.id() << std::endl ;
  o << " parents : " ;
  for(unsigned i=0,N=value.parents_size(); i<N ; ++i)
    o << value.parents(i) << " " ; // the problem is here
  o << std::endl ;
  o << " daughters ): " ;
  for(unsigned i=0,N=value.daughters_size(); i<N ; ++i)
    o << value.daughters(i) << " " ; // and also here
  o << std::endl ;
  return o ;
}

and is thus calling itself over and over again if such a circular relation is found.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant