You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
probably should be:
if self.next_class >= CLASS_SIZE {
constCLASS_SIZE:usize = 256;fnnew() -> DfaClasses{DfaClasses{classes:[0;CLASS_SIZE],next_class:1,}}fnadd(&mutself,b:u8){ifself.next_class > CLASS_SIZE{panic!("added too many classes")}self.classes[b asusize] = self.next_classasu8;self.next_class += 1;}
May use controlled conversion to u8:
use std::convert::TryInto;pubfnmain(){// 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 conversionlet 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);}
The text was updated successfully, but these errors were encountered:
Good catch. Patches welcome. Note that this error is impossible to trigger though, because the number of classes is always quite small and there is no way to make it bigger.
Yes, that's right.
But, nobody bothers to do this:
const CLASS_SIZE: usize = 3; ;-)
This issue was found by my colleage who just has no github account, so I'd written instead of him, and so I hardly supply a patch (Alas, don't know Rust). But. I have a side question: do you have benchmark statistics of this csv-reader on some of CSV-files (game.csv, for example). Could you give me a link?
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 {
May use controlled conversion to u8:
The text was updated successfully, but these errors were encountered: