Skip to content

Commit 3a6da7f

Browse files
authored
Merge pull request #748 from elbeno/fix-mipi-size-calc
🐛 Fix mipi catalog payload size calculation
2 parents d08c713 + 501929a commit 3a6da7f

File tree

2 files changed

+17
-8
lines changed

2 files changed

+17
-8
lines changed

include/log/catalog/mipi_builder.hpp

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -67,22 +67,20 @@ template <packer P> struct builder<defn::catalog_msg_t, P> {
6767
template <auto Level, typename... Ts>
6868
static auto build(string_id id, module_id m, Ts... args) {
6969
using namespace msg;
70-
if constexpr ((0 + ... + sizeof(Ts)) <= sizeof(std::uint32_t) * 2) {
70+
constexpr auto payload_size =
71+
(sizeof(id) + ... + sizeof(typename P::template pack_as_t<Ts>));
72+
if constexpr (payload_size <= sizeof(uint32_t) * 3) {
7173
constexpr auto header_size =
7274
defn::catalog_msg_t::size<std::uint32_t>::value;
73-
constexpr auto payload_size =
74-
stdx::sized8{(sizeof(id) + ... +
75-
sizeof(typename P::template pack_as_t<Ts>))}
76-
.in<std::uint32_t>();
7775
using storage_t =
78-
std::array<std::uint32_t, header_size + payload_size>;
76+
std::array<std::uint32_t,
77+
header_size +
78+
stdx::sized8{payload_size}.in<std::uint32_t>()>;
7979
return catalog_builder<storage_t, P>{}.template build<Level>(
8080
id, m, args...);
8181
} else {
8282
constexpr auto header_size =
8383
defn::catalog_msg_t::size<std::uint8_t>::value;
84-
constexpr auto payload_size =
85-
(sizeof(id) + ... + sizeof(typename P::template pack_as_t<Ts>));
8684
using storage_t =
8785
std::array<std::uint8_t, header_size + payload_size>;
8886
return catalog_builder<storage_t, P>{}.template build<Level>(

test/log/encoder.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -259,6 +259,17 @@ TEST_CASE("log more than two arguments", "[mipi]") {
259259
}
260260
}
261261

262+
TEST_CASE("log more than two arguments whose size fits in two uint32_ts",
263+
"[mipi]") {
264+
CIB_LOG_ENV(logging::get_level, logging::level::TRACE);
265+
test_critical_section::count = 0;
266+
auto cfg = logging::binary::config{
267+
test_log_buf_destination<logging::level::TRACE, log_env, 42u, 'a', 'b',
268+
'c'>{}};
269+
cfg.logger.log_msg<log_env>(stdx::ct_format<"{} {} {}">('a', 'b', 'c'));
270+
CHECK(test_critical_section::count == 2);
271+
}
272+
262273
TEST_CASE("log to multiple destinations", "[mipi]") {
263274
CIB_LOG_ENV(logging::get_level, logging::level::TRACE);
264275
test_critical_section::count = 0;

0 commit comments

Comments
 (0)