BurntSushi / BurntSushi/rust-csv
Issue in reader
- Dominant language
- Rust
- Stars
- 2k
- Forks
- 257
- PR merge metrics
- No merged PRs in 30d
Description
# Possible error in code: file reader.rs
Check code if self.next_class = 255
existing code:
if self.next_class > CLASS_SIZE {
probably should be:
if self.next_class >= CLASS_SIZE {
```rust
const CLASS_SIZE: usize = 256;
fn new() -> DfaClasses {
DfaClasses {
classes: [0; CLASS_SIZE],
next_class: 1,
}
}
fn add(&mut self, b: u8) {
if self.next_class > CLASS_SIZE {
panic!("added too many classes")
}
self.classes[b as usize] = self.next_class as u8;
self.next_class += 1;
}
```
May use controlled conversion to u8:
```rust
use std::convert::TryInto;
pub fn main() {
// let mut c = DfaClasses::new();
let b: u32 = 256;
//let xxx: u8 = b as u8; // -> ignore overfow
//let xxx: u8 = b.try_into().unwrap(); // -> runtime error: out of range in conversion
let xxx: u8 = match b.try_into() {
Result::Ok(b2) => b2,
Result::Err(e2) => {
println!("Error: {}", e2);
0
}
}; // -> Error: out of range integral type conversion attempted
// c.next_class = 255;
// println!("{}", c.next_class);
// c.add(123);
// println!("{}", c.next_class);
// c.add(123);
println!("xxx = {}", xxx);
}
```
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.