diff --git a/Cargo.toml b/Cargo.toml index 67ed111..8bc97f2 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "readformat" -version = "0.1.0" +version = "0.1.1" edition = "2021" repository = "https://github.com/tudbut/readformat" license = "MIT" diff --git a/src/lib.rs b/src/lib.rs index 39a2baf..9116128 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -26,6 +26,9 @@ pub fn readf(format: &str, mut s: &str) -> Option> { for n in 0..=occurences { // shave off space until next {} let i = if let Some(x) = f.find("{}") { x } else { f.len() }; + if f.len() <= i || s.len() <= i { + return None; + } if &f[0..i] != &s[0..i] { return None; }