1
0
mirror of https://github.com/TomHarte/CLK.git synced 2026-04-26 19:17:52 +00:00

Ensure header is safely placed.

This commit is contained in:
Thomas Harte
2025-12-02 18:08:23 -05:00
parent 30d85a9d13
commit fd5e26f84a
2 changed files with 30 additions and 13 deletions
+8 -5
View File
@@ -125,11 +125,14 @@ uint8_t Header::type_descriptor() const {
}
}
void Header::serialise(uint8_t *target, [[maybe_unused]] uint16_t length) const {
void Header::serialise(uint8_t *target, uint16_t length) const {
target[0] = type_descriptor();
// TODO: validate length.
std::memcpy(&target[1], data.data(), 191);
const auto bytes_to_copy = std::min(size_t(length), data.size());
std::copy(
data.begin(),
data.begin() + ptrdiff_t(bytes_to_copy),
target
);
}
std::unique_ptr<Data> Parser::get_next_data_body(Storage::Tape::TapeSerialiser &serialiser, bool is_original) {
@@ -148,7 +151,7 @@ std::unique_ptr<Data> Parser::get_next_data_body(Storage::Tape::TapeSerialiser &
data->data.push_back(get_next_byte_contents(serialiser));
}
// the above has reead the parity byte to the end of the data; if it matched the calculated parity it'll now be zero
// the above has read the parity byte to the end of the data; if it matched the calculated parity it'll now be zero
data->parity_was_valid = !get_parity_byte();
data->duplicate_matched = false;