From 35bd16f11347afe12ded62819a21b7df36333484 Mon Sep 17 00:00:00 2001 From: Kelbon Nik Date: Sat, 19 Oct 2024 11:56:44 +0400 Subject: [PATCH] add decoder precondition comment --- include/hpack/decoder.hpp | 3 +++ src/decoder.cpp | 3 +++ 2 files changed, 6 insertions(+) diff --git a/include/hpack/decoder.hpp b/include/hpack/decoder.hpp index 32330bf..bf60da6 100644 --- a/include/hpack/decoder.hpp +++ b/include/hpack/decoder.hpp @@ -121,6 +121,7 @@ struct header_view { } }; +// precondition: in != e void decode_string(In& in, In e, decoded_string& out); struct decoder { @@ -139,10 +140,12 @@ struct decoder { https://www.rfc-editor.org/rfc/rfc7540#section-8.1.2.5 and protocol error if decoded header name is not lowercase */ + // precondition: in != e void decode_header(In& in, In e, header_view& out); // returns status code // its always first header of response, so 'in' must point to first byte of headers block + // precondition: in != e int decode_response_status(In& in, In e); }; diff --git a/src/decoder.cpp b/src/decoder.cpp index 7c65a6a..3ecad6b 100644 --- a/src/decoder.cpp +++ b/src/decoder.cpp @@ -153,6 +153,7 @@ static size_type decode_dynamic_table_size_update(In& in, In e) noexcept { } void decode_string(In& in, In e, decoded_string& out) { + assert(in != e); bool is_huffman = *in & 0b1000'0000; size_type str_len = decode_integer(in, e, 7); if (str_len > std::distance(in, e)) @@ -165,6 +166,7 @@ void decode_string(In& in, In e, decoded_string& out) { } void decoder::decode_header(In& in, In e, header_view& out) { + assert(in != e); if (*in & 0b1000'0000) return decode_header_fully_indexed(in, e, dyntab, out); if (*in & 0b0100'0000) @@ -183,6 +185,7 @@ void decoder::decode_header(In& in, In e, header_view& out) { } int decoder::decode_response_status(In& in, In e) { + assert(in != e); if (*in & 0b1000'0000) { // fast path, fully indexed auto in_before = in;