From 24e2a0d441654da76ed8c43ec0c92bc8e0763bdb Mon Sep 17 00:00:00 2001 From: TudbuT Date: Sun, 1 Jan 2023 20:01:55 +0100 Subject: [PATCH] fix a crash --- Cargo.toml | 2 +- src/lib.rs | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) 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; }