gyscos / gyscos/cursive

Inconsistency between documentation and code implementation

Open
#772 4 comments 0 reactions 0 assignees View on GitHub
bug
Dominant language
Rust
Stars
4.8k
Forks
270
Avg merge
5d 19h
Merged PRs (30d)
2

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.
```rust
/// 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
```rust
/// 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()`"
```rust
/// Panics if `i > self.len()`.
pub fn insert_child(&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();
}
```

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.