spirit-code / spirit

Atomistic Spin Simulation Framework
http://spirit-code.github.io
MIT License
118 stars 52 forks source link

`Geometry_Set_N_Cells` doesn't validate input #603

Open GPMueller opened 3 years ago

GPMueller commented 3 years ago

The entire function currently reads

    // The new number of basis cells
    auto n_cells = intfield{n_cells_i[0], n_cells_i[1], n_cells_i[2]};

    // The new geometry
    auto& old_geometry = *state->active_image->geometry;
    auto  new_geometry = Data::Geometry(old_geometry.bravais_vectors, n_cells, old_geometry.cell_atoms,
                        old_geometry.cell_composition, old_geometry.lattice_constant,
                        old_geometry.pinning, old_geometry.defects);

    // Update the State
    Helper_State_Set_Geometry(state, old_geometry, new_geometry);

    Log(Utility::Log_Level::Warning, Utility::Log_Sender::API, fmt::format("Set number of cells for all Systems: ({}, {}, {})", n_cells[0], n_cells[1], n_cells[2]), -1, -1);

This needs to be fixed! The ImGUI can be crashed by setting a zero in the GeometryWidget.