Skip to content

Commit

Permalink
Fix remaining clippy warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
gtsiam committed Nov 27, 2022
1 parent 1c87a87 commit 229367b
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 8 deletions.
17 changes: 10 additions & 7 deletions src/frame/headers.rs
Expand Up @@ -309,17 +309,20 @@ impl fmt::Debug for Headers {

// ===== util =====

pub fn parse_u64(src: &[u8]) -> Result<u64, ()> {
#[derive(Debug)]
pub struct ParseU64Error;

pub fn parse_u64(src: &[u8]) -> Result<u64, ParseU64Error> {
if src.len() > 19 {
// At danger for overflow...
return Err(());
return Err(ParseU64Error);
}

let mut ret = 0;

for &d in src {
if !(b'0'..=b'9').contains(&d) {
return Err(());
return Err(ParseU64Error);
}

ret *= 10;
Expand All @@ -333,7 +336,7 @@ pub fn parse_u64(src: &[u8]) -> Result<u64, ()> {

#[derive(Debug)]
pub enum PushPromiseHeaderError {
InvalidContentLength(Result<u64, ()>),
InvalidContentLength(Result<u64, ParseU64Error>),
NotSafeAndCacheable,
}

Expand Down Expand Up @@ -364,9 +367,9 @@ impl PushPromise {
// A promised request "that indicates the presence of a request body
// MUST reset the promised stream with a stream error"
if let Some(content_length) = req.headers().get(header::CONTENT_LENGTH) {
let parsed_length = parse_u64(content_length.as_bytes());
if parsed_length != Ok(0) {
return Err(InvalidContentLength(parsed_length));
match parse_u64(content_length.as_bytes()) {
Ok(0) => (),
parsed => return Err(InvalidContentLength(parsed)),
}
}
// "The server MUST include a method in the :method pseudo-header field
Expand Down
1 change: 1 addition & 0 deletions src/proto/streams/mod.rs
Expand Up @@ -7,6 +7,7 @@ mod send;
mod state;
mod store;
mod stream;
#[allow(clippy::module_inception)]
mod streams;

pub(crate) use self::prioritize::Prioritized;
Expand Down
3 changes: 2 additions & 1 deletion src/proto/streams/recv.rs
Expand Up @@ -178,7 +178,7 @@ impl Recv {
if let Some(content_length) = frame.fields().get(header::CONTENT_LENGTH) {
let content_length = match frame::parse_u64(content_length.as_bytes()) {
Ok(v) => v,
Err(()) => {
Err(_) => {
proto_err!(stream: "could not parse content-length; stream={:?}", stream.id);
return Err(Error::library_reset(stream.id, Reason::PROTOCOL_ERROR).into());
}
Expand Down Expand Up @@ -263,6 +263,7 @@ impl Recv {
}

/// Called by the client to get pushed response
#[allow(clippy::type_complexity)]
pub fn poll_pushed(
&mut self,
cx: &Context,
Expand Down
1 change: 1 addition & 0 deletions src/proto/streams/streams.rs
Expand Up @@ -1267,6 +1267,7 @@ impl OpaqueStreamRef {
me.actions.recv.poll_response(cx, &mut stream)
}
/// Called by a client to check for a pushed request.
#[allow(clippy::type_complexity)]
pub fn poll_pushed(
&mut self,
cx: &Context,
Expand Down
1 change: 1 addition & 0 deletions src/server.rs
Expand Up @@ -407,6 +407,7 @@ where
}

#[doc(hidden)]
#[allow(clippy::type_complexity)]
pub fn poll_accept(
&mut self,
cx: &mut Context<'_>,
Expand Down

0 comments on commit 229367b

Please sign in to comment.