Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 17 additions & 4 deletions src/Bytes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,13 @@ void Bytes::assignHex(const uint8_t* hex, size_t hex_size) {
_exclusive = true;
return;
}
// Truncate to even length (hex bytes come in pairs)
hex_size &= ~(size_t)1;
if (hex_size == 0) {
_data = nullptr;
_exclusive = true;
return;
}
exclusiveData(false, hex_size / 2);
// need to clear data since we're appending below
_data->clear();
Expand All @@ -140,6 +147,11 @@ void Bytes::appendHex(const uint8_t* hex, size_t hex_size) {
if (hex == nullptr || hex_size <= 0) {
return;
}
// Truncate to even length (hex bytes come in pairs)
hex_size &= ~(size_t)1;
if (hex_size == 0) {
return;
}
exclusiveData(true, size() + (hex_size / 2));
for (size_t i = 0; i < hex_size; i += 2) {
uint8_t byte = (hex[i] % 32 + 9) % 25 * 16 + (hex[i+1] % 32 + 9) % 25;
Expand Down Expand Up @@ -186,10 +198,11 @@ Bytes Bytes::mid(size_t beginpos, size_t len) const {
if (!_data || beginpos >= size()) {
return NONE;
}
if ((beginpos + len) >= size()) {
len = (size() - beginpos);
}
return {data() + beginpos, len};
size_t remaining = size() - beginpos;
if (len > remaining) {
len = remaining;
}
return {data() + beginpos, len};
}

// to end
Expand Down
8 changes: 4 additions & 4 deletions src/Transport.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -318,8 +318,8 @@ using namespace RNS::Utilities;
}
}
// CBA since modifying of collection while iterating is forbidden
for (auto& receipt : _receipts) {
cull_receipts.remove(receipt);
for (auto& receipt : cull_receipts) {
_receipts.remove(receipt);
}

_receipts_last_checked = OS::time();
Expand Down Expand Up @@ -2274,8 +2274,8 @@ using namespace RNS::Utilities;
}
}
// CBA since modifying of collection while iterating is forbidden
for (auto& receipt : _receipts) {
cull_receipts.remove(receipt);
for (auto& receipt : cull_receipts) {
_receipts.remove(receipt);
}
}
}
Expand Down
Loading