Open
Description
I noticed a possible panic due to inconsistency between documentation and code implementation in cursive-main/cursive-core/src/views/linear_layout.rs. The details can be found in the following code. The code does not check whether i is out of bounds before use it directly.
/// Panics if `i >= self.len()`.
pub fn set_weight(&mut self, i: usize, weight: usize) {
self.children[i]._weight = weight;
}
The similar situation can be found in cursive-main/cursive-core/src/views/list_view.rs
/// Panics if `id >= self.len()`.
pub fn row_mut(&mut self, id: usize) -> &mut ListChild {
&mut self.children[id]
}
Besides I think this documentation in cursive-main/cursive-core/src/views/linear_layout.rs is not complete, which should be "Panics if i >= self.len()
" instead of "Panics if i > self.len()
"
/// Panics if `i > self.len()`.
pub fn insert_child<V: IntoBoxedView + 'static>(&mut self, i: usize, view: V) {
self.children.insert(
i,
Child {
view: view.into_boxed_view(),
required_size: Vec2::zero(),
last_size: Vec2::zero(),
_weight: 0,
},
);
self.invalidate();
}