Skip to content

Conversation

@zfields
Copy link
Contributor

@zfields zfields commented Jan 30, 2026

No description provided.

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds Catch2 unit coverage for COBS helper functions and adjusts COBS sizing helpers to better handle edge cases (notably zero-length inputs) and centralize constants.

Changes:

  • Added new Catch2 test suites covering _cobsDecode, _cobsEncode, _cobsEncodedLength, _cobsEncodedMaxLength, and _cobsGuaranteedFit.
  • Registered the new COBS tests in the test CMake target list.
  • Updated n_cobs.c to introduce COBS_MAX_PACKET_SIZE and revise _cobsEncodedMaxLength / _cobsGuaranteedFit calculations.

Reviewed changes

Copilot reviewed 7 out of 7 changed files in this pull request and generated 8 comments.

Show a summary per file
File Description
test/src/_cobsGuaranteedFit_test.cpp Adds unit tests for _cobsGuaranteedFit across boundary conditions.
test/src/_cobsEncodedMaxLength_test.cpp Adds unit tests for _cobsEncodedMaxLength, including length=0.
test/src/_cobsEncodedLength_test.cpp Adds unit tests for _cobsEncodedLength correctness and input immutability.
test/src/_cobsEncode_test.cpp Adds unit tests for _cobsEncode, including in-place encoding and non-zero EOP.
test/src/_cobsDecode_test.cpp Adds unit tests for _cobsDecode, including in-place decoding and non-zero EOP.
test/CMakeLists.txt Registers the new COBS unit test executables with CTest discovery.
n_cobs.c Centralizes max packet size constant and updates worst-case sizing/fit computations.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@zfields
Copy link
Contributor Author

zfields commented Jan 30, 2026

Unit-test error generated by Valgrind:

GIVEN A specified EOP byte of 0x00
AND_GIVEN An array capable of being COBS-encoded in-place
WHEN The array is COBS-encoded in-place

==32108== Memcheck, a memory error detector
==32108== Copyright (C) 2002-2024, and GNU GPL'd, by Julian Seward et al.
==32108== Using Valgrind-3.24.0 and LibVEX; rerun with -h for copyright info
==32108== Command: /workspaces/note-c/build/test/_cobsEncode_test Scenario:\ _cobsEncode
==32108== Parent PID: 32096
==32108== 
==32108== Source and destination overlap in memcpy(0xfef05a86, 0xfef05a86, 1)
==32108==    at 0x484DE20: memcpy (vg_replace_strmem.c:1150)
==32108==    by 0x486E863: _cobsEncode (n_cobs.c:149)
==32108==    by 0x112954: (anonymous namespace)::CATCH2_INTERNAL_TEST_0() (_cobsEncode_test.cpp:35)
==32108==    by 0x182D73: Catch::TestInvokerAsFunction::invoke() const (in /workspaces/note-c/build/test/_cobsEncode_test)
==32108==    by 0x1777E3: Catch::TestCaseHandle::invoke() const (in /workspaces/note-c/build/test/_cobsEncode_test)
==32108==    by 0x176BDB: Catch::RunContext::invokeActiveTestCase() (in /workspaces/note-c/build/test/_cobsEncode_test)
==32108==    by 0x17692F: Catch::RunContext::runCurrentTest(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >&) (in /workspaces/note-c/build/test/_cobsEncode_test)
==32108==    by 0x1751D7: Catch::RunContext::runTest(Catch::TestCaseHandle const&) (in /workspaces/note-c/build/test/_cobsEncode_test)
==32108==    by 0x12BAFC: Catch::(anonymous namespace)::TestGroup::execute() (in /workspaces/note-c/build/test/_cobsEncode_test)
==32108==    by 0x12CEEB: Catch::Session::runInternal() (in /workspaces/note-c/build/test/_cobsEncode_test)
==32108==    by 0x12CA66: Catch::Session::run() (in /workspaces/note-c/build/test/_cobsEncode_test)
==32108==    by 0x129122: int Catch::Session::run<char>(int, char const* const*) (in /workspaces/note-c/build/test/_cobsEncode_test)
==32108== 
==32108== 
==32108== HEAP SUMMARY:
==32108==     in use at exit: 0 bytes in 0 blocks
==32108==   total heap usage: 4,786 allocs, 4,786 frees, 485,384 bytes allocated
==32108== 
==32108== All heap blocks were freed -- no leaks are possible
==32108== 
==32108== For lists of detected and suppressed errors, rerun with: -s
==32108== ERROR SUMMARY: 6 errors from 1 contexts (suppressed: 0 from 0)

UPDATE: memcpy -> memmove (resolved this issue)

@zfields zfields merged commit 2bac147 into master Jan 30, 2026
23 of 24 checks passed
@zfields zfields deleted the zak-cobs branch January 30, 2026 17:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants