fix(cpn): prevent drag'n'drop and paste if incompatible boards#7376
fix(cpn): prevent drag'n'drop and paste if incompatible boards#7376elecpower wants to merge 2 commits into
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (2)
🚧 Files skipped from review as they are similar to previous changes (1)
📝 WalkthroughWalkthroughModelsListModel drag-and-drop MIME header now includes board type and a version macro; model payloads no longer embed board. Incoming MIME is checked for board compatibility before counting or accepting model drops. ChangesBoard-aware MIME drag-and-drop validation
Sequence DiagramsequenceDiagram
participant Source as Source Instance
participant SourceModel as Source ModelsListModel
participant MIME as MIME Header
participant TargetModel as Target ModelsListModel
Source->>SourceModel: create mimeHeaderData {version=2, board}
SourceModel->>MIME: encodeHeaderData(stream: version, instanceId, board)
SourceModel->>Source: encodeModelsData(payload: mdlCnt, modelBuffers...)
Source->>TargetModel: drag with MIME(header, payload)
TargetModel->>MIME: decodeHeaderData()
TargetModel->>TargetModel: getMimeDataBoard()
TargetModel->>TargetModel: hasCompatibleBoardMimeData()?
alt compatible
TargetModel->>TargetModel: countModelsInMimeData() -> read mdlCnt, parse models
TargetModel->>TargetModel: accept drop
else incompatible
TargetModel->>TargetModel: reject drop
end
🎯 3 (Moderate) | ⏱️ ~25 minutes 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Comment |
There was a problem hiding this comment.
Actionable comments posted: 2
🧹 Nitpick comments (1)
companion/src/modelslist.cpp (1)
771-776: 💤 Low valueConsider checking
decodeHeaderDatareturn value.If
decodeHeaderDatafails (no header present),header.boardwill be whatever the struct defaults to. This is safe if the struct is properly initialized (see earlier comment), but checking the return value makes intent explicit.♻️ Optional defensive check
Board::Type ModelsListModel::getMimeDataBoard(const QMimeData * mimeData) const { MimeHeaderData header; - decodeHeaderData(mimeData, &header); + if (!decodeHeaderData(mimeData, &header)) + return Board::BOARD_UNKNOWN; return header.board; }🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@companion/src/modelslist.cpp` around lines 771 - 776, In ModelsListModel::getMimeDataBoard, call decodeHeaderData(mimeData, &header) and check its return value; if it returns false, return a safe default (e.g., a default-constructed Board::Type or a known sentinel such as Board::Invalid) instead of unconditionally returning header.board—only return header.board when decodeHeaderData succeeds to make the intent explicit and defensive.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@companion/src/modelslist.cpp`:
- Line 519: The code unconditionally extracts header->board after reading
header->dataVersion and header->instanceId, which breaks on v1 headers that lack
board; modify the reader in modelslist.cpp to first read header->dataVersion and
header->instanceId, check header->dataVersion (e.g., if >= 2) before attempting
to extract header->board, and for older versions set header->board to a safe
default; also validate the stream state after each extraction (or before
returning true) so failures set the stream/error and the function returns false
instead of leaving header->board uninitialized.
In `@companion/src/modelslist.h`:
- Around line 83-87: The MimeHeaderData struct members should be initialized to
safe defaults to avoid uninitialized `board` when decodeHeaderData fails or
parses older headers; add default member initializers in the MimeHeaderData
definition (e.g., set instanceId to QUuid(), dataVersion to 0, and board to
Board::Type() or an explicit sentinel) so getMimeDataBoard and
hasCompatibleBoardMimeData see a well-defined value; if there are constructors
that set these fields, ensure they also initialize all three members.
---
Nitpick comments:
In `@companion/src/modelslist.cpp`:
- Around line 771-776: In ModelsListModel::getMimeDataBoard, call
decodeHeaderData(mimeData, &header) and check its return value; if it returns
false, return a safe default (e.g., a default-constructed Board::Type or a known
sentinel such as Board::Invalid) instead of unconditionally returning
header.board—only return header.board when decodeHeaderData succeeds to make the
intent explicit and defensive.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro Plus
Run ID: a4cb4501-ad66-4b64-8dfd-ba39527f0b4b
📒 Files selected for processing (2)
companion/src/modelslist.cppcompanion/src/modelslist.h
Fixes #3950
Summary of changes:
Summary by CodeRabbit