From 0d896f650d80e21a7237a54728a52bf9beb84d18 Mon Sep 17 00:00:00 2001 From: Bryan Biedenkapp Date: Thu, 6 Aug 2026 09:42:21 -0400 Subject: [PATCH] code cleanup; --- tests/ProtocolParser_Robustness_Tests.cpp | 16 ++++++++++++++++ tests/dmr/HostControl_Tests.cpp | 2 +- tests/nxdn/HostControl_Tests.cpp | 2 +- tests/p25/HostControl_Tests.cpp | 2 +- 4 files changed, 19 insertions(+), 3 deletions(-) diff --git a/tests/ProtocolParser_Robustness_Tests.cpp b/tests/ProtocolParser_Robustness_Tests.cpp index 891f39b6..79635cc3 100644 --- a/tests/ProtocolParser_Robustness_Tests.cpp +++ b/tests/ProtocolParser_Robustness_Tests.cpp @@ -30,7 +30,16 @@ using namespace nxdn::channel; using namespace p25::defines; using namespace p25::lc::tsbk; +// --------------------------------------------------------------------------- +// Global Functions +// --------------------------------------------------------------------------- namespace { + +/** + * @brief Generate a pseudo-random number using xorshift32. + * @param state Reference to the current state of the random number generator. + * @returns uint32_t Pseudo-random number. + */ uint32_t nextRand(uint32_t& state) { // Deterministic xorshift32 for reproducible fuzz vectors. @@ -40,12 +49,19 @@ uint32_t nextRand(uint32_t& state) return state; } +/** + * @brief Fill a buffer with pseudo-random data. + * @param buffer Pointer to the buffer to fill. + * @param len Length of the buffer in bytes. + * @param state Reference to the current state of the random number generator. + */ void fillPseudoRandom(uint8_t* buffer, uint32_t len, uint32_t& state) { for (uint32_t i = 0U; i < len; ++i) { buffer[i] = static_cast(nextRand(state) & 0xFFU); } } + } // namespace TEST_CASE("Parsers tolerate malformed inputs without throwing", "[robustness][fuzz][parser]") diff --git a/tests/dmr/HostControl_Tests.cpp b/tests/dmr/HostControl_Tests.cpp index f1fe9e29..82b8ae26 100644 --- a/tests/dmr/HostControl_Tests.cpp +++ b/tests/dmr/HostControl_Tests.cpp @@ -157,7 +157,7 @@ void buildDMRVoiceSyncPayload(uint8_t* payload) dmr::Sync::addDMRAudioSync(payload, false); } -} +} // namespace // --------------------------------------------------------------------------- // Class Declaration diff --git a/tests/nxdn/HostControl_Tests.cpp b/tests/nxdn/HostControl_Tests.cpp index 6e6cbf51..c3d2caa9 100644 --- a/tests/nxdn/HostControl_Tests.cpp +++ b/tests/nxdn/HostControl_Tests.cpp @@ -98,7 +98,7 @@ uint16_t reserveLoopbackPort() return ntohs(address.sin_port); } -} +} // namespace // --------------------------------------------------------------------------- // Class Declaration diff --git a/tests/p25/HostControl_Tests.cpp b/tests/p25/HostControl_Tests.cpp index ffe63763..4152e71a 100644 --- a/tests/p25/HostControl_Tests.cpp +++ b/tests/p25/HostControl_Tests.cpp @@ -142,7 +142,7 @@ void buildP25RFFrame(const uint8_t* payload, uint8_t* frame) ::memcpy(frame + 2U, payload, p25::defines::P25_LDU_FRAME_LENGTH_BYTES); } -} +} // namespace // --------------------------------------------------------------------------- // Class Declaration