mirror of
https://github.com/ratspeak/microReticulum
synced 2026-11-27 13:52:14 +00:00
Add announce table culling, fix use-after-free, and refactor build/log
- Add cull_announce_table() with OOM-safe min_element fallback, matching pattern from cull_path_table() and cull_known_destinations() - Call cull immediately after every announce/path/known-destination insert - Fix use-after-free: guard announce_entry access with announce_erased flag - remove_path() now also deletes cached packet files - Path table insert now removes existing entry first to prevent duplicates - Rename env:mcu -> env:embedded; add env:native_debug and heltec_wifi_lora_32_V4 - Make TLSF buffer size configurable via RNS_TLSF_BUFFER_SIZE macro - Refactor log macros to unified RNS::log() path; add doHeadLog with callback support - Prefix all bad_alloc error messages with "bad_alloc -" for easier grepping
This commit is contained in:
1 parent
086aac87b5
commit
e86481e121
15 files changed
+891
-403
No files matched your search
@@ -569,6 +569,83 @@ void testIndex() {
|
||||
TEST_ASSERT_EQUAL_UINT8('o', bytes[4]);
|
||||
}
|
||||
|
||||
// ============================================================================
|
||||
// Bytes edge case tests
|
||||
// ============================================================================
|
||||
|
||||
void test_assignHex_even_length() {
|
||||
// Normal case: even-length hex string
|
||||
RNS::Bytes bytes;
|
||||
bytes.assignHex("48656C6C6F"); // "Hello"
|
||||
TEST_ASSERT_EQUAL_size_t(5, bytes.size());
|
||||
TEST_ASSERT_EQUAL_MEMORY("Hello", bytes.data(), 5);
|
||||
}
|
||||
|
||||
void test_assignHex_odd_length() {
|
||||
// Odd-length hex should be truncated to even (drop trailing nibble)
|
||||
RNS::Bytes bytes;
|
||||
bytes.assignHex("ABC"); // 3 chars - only "AB" should be decoded
|
||||
TEST_ASSERT_EQUAL_size_t(1, bytes.size());
|
||||
TEST_ASSERT_EQUAL_UINT8(0xAB, bytes.data()[0]);
|
||||
}
|
||||
|
||||
void test_assignHex_single_char() {
|
||||
// Single char hex can't form a complete byte - should produce empty
|
||||
RNS::Bytes bytes;
|
||||
bytes.assignHex("A");
|
||||
TEST_ASSERT_EQUAL_size_t(0, bytes.size());
|
||||
}
|
||||
|
||||
void test_assignHex_empty() {
|
||||
RNS::Bytes bytes;
|
||||
bytes.assignHex("");
|
||||
TEST_ASSERT_EQUAL_size_t(0, bytes.size());
|
||||
}
|
||||
|
||||
void test_appendHex_odd_length() {
|
||||
// appendHex with odd length should also truncate to even
|
||||
RNS::Bytes bytes;
|
||||
bytes.assignHex("4142"); // "AB"
|
||||
TEST_ASSERT_EQUAL_size_t(2, bytes.size());
|
||||
|
||||
bytes.appendHex("434"); // 3 chars - only "43" ('C') should be appended
|
||||
TEST_ASSERT_EQUAL_size_t(3, bytes.size());
|
||||
TEST_ASSERT_EQUAL_UINT8(0x43, bytes.data()[2]);
|
||||
}
|
||||
|
||||
void test_hex_roundtrip_stability() {
|
||||
// toHex always produces even length, so roundtrip should be safe
|
||||
RNS::Bytes original("Hello World");
|
||||
std::string hex = original.toHex();
|
||||
TEST_ASSERT_TRUE(hex.length() % 2 == 0); // Must be even
|
||||
|
||||
RNS::Bytes restored;
|
||||
restored.assignHex(hex.c_str());
|
||||
TEST_ASSERT_EQUAL_size_t(original.size(), restored.size());
|
||||
TEST_ASSERT_EQUAL_MEMORY(original.data(), restored.data(), original.size());
|
||||
}
|
||||
|
||||
void test_mid_large_len() {
|
||||
// mid() with len that extends past end should clamp
|
||||
RNS::Bytes bytes("Hello World");
|
||||
|
||||
RNS::Bytes mid = bytes.mid(3, 100);
|
||||
TEST_ASSERT_EQUAL_size_t(8, mid.size());
|
||||
TEST_ASSERT_EQUAL_MEMORY("lo World", mid.data(), 8);
|
||||
|
||||
// SIZE_MAX len should also clamp, not integer-overflow and crash
|
||||
RNS::Bytes mid2 = bytes.mid(3, SIZE_MAX);
|
||||
TEST_ASSERT_EQUAL_size_t(8, mid2.size());
|
||||
TEST_ASSERT_EQUAL_MEMORY("lo World", mid2.data(), 8);
|
||||
}
|
||||
|
||||
void test_mid_zero_size_bytes() {
|
||||
RNS::Bytes empty;
|
||||
RNS::Bytes mid = empty.mid(0, 5);
|
||||
TEST_ASSERT_FALSE(mid);
|
||||
TEST_ASSERT_EQUAL_size_t(0, mid.size());
|
||||
}
|
||||
|
||||
|
||||
void setUp(void) {
|
||||
// set stuff up here before each test
|
||||
@@ -598,6 +675,16 @@ int runUnityTests(void) {
|
||||
RUN_TEST(testConcat);
|
||||
RUN_TEST(testIndex);
|
||||
|
||||
// Bytes edge cases
|
||||
RUN_TEST(test_assignHex_even_length);
|
||||
RUN_TEST(test_assignHex_odd_length);
|
||||
RUN_TEST(test_assignHex_single_char);
|
||||
RUN_TEST(test_assignHex_empty);
|
||||
RUN_TEST(test_appendHex_odd_length);
|
||||
RUN_TEST(test_hex_roundtrip_stability);
|
||||
RUN_TEST(test_mid_large_len);
|
||||
RUN_TEST(test_mid_zero_size_bytes);
|
||||
|
||||
// Suite-level teardown
|
||||
size_t post_memory = RNS::Utilities::OS::heap_available();
|
||||
size_t diff_memory = (int)pre_memory - (int)post_memory;
|
||||
|
||||
Reference in new issue
Block a user