mirror of
https://codeberg.org/icewind/tf-log-parser.git
synced 2026-06-03 10:14:10 +02:00
parse int overflow as max
This commit is contained in:
parent
b95c58a257
commit
8b94c0d515
1 changed files with 40 additions and 4 deletions
|
|
@ -220,10 +220,46 @@ impl<'a, T: EventFieldFromStr + 'a> EventField<'a> for T {
|
|||
}
|
||||
|
||||
impl EventFieldFromStr for SocketAddr {}
|
||||
impl EventFieldFromStr for u8 {}
|
||||
impl EventFieldFromStr for u32 {}
|
||||
impl EventFieldFromStr for i32 {}
|
||||
impl EventFieldFromStr for i64 {}
|
||||
|
||||
fn parse_int_overflow<T: FromStr>(input: &str, max: T) -> Result<T> {
|
||||
match parse_from_str(input) {
|
||||
Err(e) => {
|
||||
if input.bytes().all(|b| b.is_ascii_digit()) {
|
||||
Ok(max)
|
||||
} else {
|
||||
Err(e)
|
||||
}
|
||||
}
|
||||
r => r,
|
||||
}
|
||||
}
|
||||
|
||||
impl EventField<'_> for u8 {
|
||||
fn parse_field(input: &str) -> Result<Self> {
|
||||
parse_int_overflow(input, Self::MAX)
|
||||
}
|
||||
}
|
||||
impl EventField<'_> for u16 {
|
||||
fn parse_field(input: &str) -> Result<Self> {
|
||||
parse_int_overflow(input, Self::MAX)
|
||||
}
|
||||
}
|
||||
impl EventField<'_> for u32 {
|
||||
fn parse_field(input: &str) -> Result<Self> {
|
||||
parse_int_overflow(input, Self::MAX)
|
||||
}
|
||||
}
|
||||
impl EventField<'_> for i32 {
|
||||
fn parse_field(input: &str) -> Result<Self> {
|
||||
parse_int_overflow(input, Self::MAX)
|
||||
}
|
||||
}
|
||||
impl EventField<'_> for i64 {
|
||||
fn parse_field(input: &str) -> Result<Self> {
|
||||
parse_int_overflow(input, Self::MAX)
|
||||
}
|
||||
}
|
||||
|
||||
impl EventFieldFromStr for f32 {}
|
||||
|
||||
impl<'a, T: EventField<'a>> EventField<'a> for (T, T, T) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue