Skip to content

MutHierarchies are unsound #79

@douweschulte

Description

@douweschulte

If you create a hierarchy you could potentially delete the selected lower levels from a higher level. For example you select (Model(0), Chain("A"), Residue(123), Conformer("ALA"), Atom("CA", 450, "C")) and then use chain.remove_atoms_by(|a| a.element() == "C") this would delete the selected atom, and would cause undefined behaviour when the atom is used afterwards.

The proposal is to create a trait with all safe functions for each level and make the levels implement it. The hierarchies can then return a trait object instead of the struct which would limit the use of the unsound functions. The unsound functions are all deleting functions and adding/inserting has to be checked thoroughly for potential issues. Any function that returns mut references to lower levels in the hierarchy also has to have a safe counterpart returning a Trait object.

Unsound:

  • Methods removing items below
  • Methods returning a &mut to an item in any level below?
  • Sort?
  • Extend (and join)?
  • Add lower level item? (what if this triggers a reallocation of the inner Vec?)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions