From b4a6ae1cb04deac58b93a3b84eb8d89b21c9f9d4 Mon Sep 17 00:00:00 2001 From: wrk Date: Wed, 28 Jun 2023 10:36:43 +0200 Subject: [PATCH] Fixed out of bounds bug --- src/format.rs | 4 ++-- src/lib.rs | 8 +++++--- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/src/format.rs b/src/format.rs index bf67f6c..6736a23 100644 --- a/src/format.rs +++ b/src/format.rs @@ -1,4 +1,4 @@ -#[derive(Clone, Copy, PartialEq, Eq)] +#[derive(Debug, Clone, Copy, PartialEq, Eq)] pub enum Format { Bold, Italics, @@ -23,7 +23,7 @@ impl std::fmt::Display for Format { } } -#[derive(Clone, Copy, PartialEq, Eq)] +#[derive(Debug, Clone, Copy, PartialEq, Eq)] pub enum Color { White, Black, diff --git a/src/lib.rs b/src/lib.rs index 2a07d38..fc49f2a 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -640,13 +640,15 @@ async fn recv( let len = new_lines.len(); for (index, line) in new_lines.into_iter().enumerate() { + if buf.len() < 2 { + continue; + } if index == len - 1 && &buf[buf.len() - 2..] != b"\r\n" { *partial_line = line.to_owned(); break; } - if line.len() != 0 { - lines.push(line.to_owned()); - } + + lines.push(line.to_owned()); } Ok(lines) }