Skip to content

Commit 866d055

Browse files
committed
Fix: Handle alignment requirements in byte_span conversion
1 parent c1d6903 commit 866d055

1 file changed

Lines changed: 4 additions & 2 deletions

File tree

test/source/byte_span_2_test.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -380,14 +380,16 @@ TEST_CASE("byte_span conversion utilities", "[byte_span][span]") {
380380
REQUIRE(buf.write(byte_span{text.data(), text.size()}) == text.size());
381381
REQUIRE(as_sv(buf.view()) == text);
382382

383-
struct point {
383+
struct alignas(4) point {
384384
float x, y;
385385
};
386386
auto p = point{1.0F, 2.0F};
387387

388+
buf.write(std::array<std::byte, 3>{}); // padding
389+
388390
REQUIRE(buf.write(byte_span{&p, 1}) == sizeof(p));
389391
const auto& result =
390-
as_value<point>(buf.view().subspan(text.size(), sizeof(p)));
392+
as_value<point>(buf.view().subspan(text.size() + 3, sizeof(p)));
391393
REQUIRE(result.x == Catch::Approx(p.x));
392394
REQUIRE(result.y == Catch::Approx(p.y));
393395
}

0 commit comments

Comments
 (0)