Skip to content

fix(cpn): initialise all serialised fields in FrSkyData::clear() - #7440

Merged
pfeerick merged 1 commit into
mainfrom
fix-frsky-clear-uninit-fields
Jul 14, 2026
Merged

fix(cpn): initialise all serialised fields in FrSkyData::clear()#7440
pfeerick merged 1 commit into
mainfrom
fix-frsky-clear-uninit-fields

Conversation

@raphaelcoeffic

@raphaelcoeffic raphaelcoeffic commented Jun 7, 2026

Copy link
Copy Markdown
Member

Summary

FrSkyData::clear() resets its members field-by-field (not via memset), and it omitted varioCenterSilent and ignoreSensorIds. Both are serialised to a model's YAML, so a freshly-cleared model emitted whatever bytes happened to be in those fields.

For varioCenterSilent (a bool written as int, read back through the radio's 1-bit field) this manifested as a non-idempotent YAML round-trip: a stray byte such as 45 was emitted on the first save, then masked to 1 on reload — so save → load → save did not converge.

Fix

Initialise both fields in clear():

varioCenterSilent = false;
...
ignoreSensorIds = false;

Regression test

companion/src/tests/frsky_clear_test.cpp poisons the storage (memset(..., 0x2D, ...)) before calling clear() and asserts both fields are reset, so it fails deterministically if a serialised field is ever left out of clear() again.

Verified locally (on the harness branch): the test fails before the fix and passes after.

Notes

🤖 Generated with Claude Code

Summary by CodeRabbit

  • Bug Fixes

    • Improved the FrSky data reset behavior to fully reinitialize additional configuration fields, preventing inconsistent values after clearing.
  • Tests

    • Added a unit test to verify the clear/reset operation initializes all serialized fields deterministically, including the updated configuration flags.

@coderabbitai

coderabbitai Bot commented Jun 7, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 41520fc6-4d8d-41ba-af87-9000a57810f2

📥 Commits

Reviewing files that changed from the base of the PR and between d99d9c6 and ea0e11f.

📒 Files selected for processing (2)
  • companion/src/firmwares/telem_data.cpp
  • companion/src/tests/frsky_clear_test.cpp
🚧 Files skipped from review as they are similar to previous changes (2)
  • companion/src/tests/frsky_clear_test.cpp
  • companion/src/firmwares/telem_data.cpp

📝 Walkthrough

Walkthrough

FrSkyData::clear() now initializes varioCenterSilent and ignoreSensorIds to false. A unit test verifies both fields are initialized after clearing a memory-poisoned object.

Changes

FrSkyData field initialization on clear

Layer / File(s) Summary
Clear method field initialization and validation
companion/src/firmwares/telem_data.cpp, companion/src/tests/frsky_clear_test.cpp
FrSkyData::clear() resets both boolean fields to false. The new test verifies deterministic initialization after clearing.

Estimated code review effort: 1 (Trivial) | ~3 minutes

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 50.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly matches the change to initialise missing FrSkyData serialised fields in clear().
Description check ✅ Passed The description covers the bug, fix, regression test, and notes, matching the template well.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix-frsky-clear-uninit-fields

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@pfeerick pfeerick added bug 🪲 Something isn't working companion Related to the companion software labels Jun 12, 2026
@pfeerick pfeerick added this to the 3.0 milestone Jun 12, 2026
FrSkyData::clear() resets its fields one by one rather than with a memset,
and it omitted varioCenterSilent and ignoreSensorIds. Both are serialised
to a model's YAML, so a freshly-cleared model emitted whatever happened to
be in those bytes. For varioCenterSilent (a bool written as int, read back
through a 1-bit radio field) this showed up as a non-idempotent round-trip:
a stray byte like 45 was emitted, then masked to 1 on reload.

Initialise both fields in clear(). Add a regression test that poisons the
storage before clearing, so it fails deterministically if a serialised
field is ever left out again.

Found via the model YAML round-trip test added in #7438; the regression
test here builds/runs once that PR reactivates the companion gtests.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@pfeerick
pfeerick force-pushed the fix-frsky-clear-uninit-fields branch from d99d9c6 to ea0e11f Compare July 13, 2026 00:14
@pfeerick
pfeerick merged commit 8a28c4a into main Jul 14, 2026
13 checks passed
@pfeerick
pfeerick deleted the fix-frsky-clear-uninit-fields branch July 14, 2026 22:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug 🪲 Something isn't working companion Related to the companion software

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants