diff --git a/src/detail/align_up.hpp b/src/detail/align_up.hpp new file mode 100644 index 00000000..89510a20 --- /dev/null +++ b/src/detail/align_up.hpp @@ -0,0 +1,32 @@ +// +// Copyright (c) 2024 Christian Mazakas +// +// Distributed under the Boost Software License, Version 1.0. (See accompanying +// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) +// +// Official repository: https://github.com/CPPAlliance/http_proto +// + +#ifndef BOOST_HTTP_PROTO_DETAIL_ALIGN_UP_HPP +#define BOOST_HTTP_PROTO_DETAIL_ALIGN_UP_HPP + +#include + +namespace boost { +namespace http_proto { +namespace detail { + +constexpr +inline +std::size_t +align_up(std::size_t s, std::size_t A) +{ + return A * ( + (s + A - 1) / A); +} + +} // detail +} // http_proto +} // boost + +#endif diff --git a/src/detail/header.cpp b/src/detail/header.cpp index d92b0772..62deadeb 100644 --- a/src/detail/header.cpp +++ b/src/detail/header.cpp @@ -27,6 +27,8 @@ #include #include +#include "align_up.hpp" + namespace boost { namespace http_proto { namespace detail { @@ -209,9 +211,7 @@ bytes_needed( size = 19; static constexpr auto A = alignof(header::entry); - // round up to alignof(A) - return A * ( - (size + A - 1) / A) + + return align_up(size, A) + (count * sizeof( header::entry)); }