Skip to content

Add sized overload for Layer::copyData#2141

Open
Dimi1010 wants to merge 9 commits into
seladb:devfrom
Dimi1010:refactor/sized-copy-data
Open

Add sized overload for Layer::copyData#2141
Dimi1010 wants to merge 9 commits into
seladb:devfrom
Dimi1010:refactor/sized-copy-data

Conversation

@Dimi1010

Copy link
Copy Markdown
Collaborator

The PR adds a overload of Layer::copyData that offers improved bounding checks against buffer overruns. It also improves the documentation of the methods.

…ze for bounded copy.

Improve documentation of `copyData`.
Comment thread Packet++/src/Layer.cpp

size_t Layer::copyData(uint8_t* dest, size_t destSize) const
{
size_t bytesToCopy = (std::min)(destSize, m_DataLen);

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

(std::min)(destSize, m_DataLen) this is written as such because Windows.h is fun and has MIN(a, b) macro, that normally conflicts with std::min. 🙂

@codecov

codecov Bot commented May 16, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 82.73%. Comparing base (6ba29cf) to head (9f5e360).

Additional details and impacted files
@@           Coverage Diff            @@
##              dev    #2141    +/-   ##
========================================
  Coverage   82.72%   82.73%            
========================================
  Files         332      332            
  Lines       59807    59835    +28     
  Branches    12591    12587     -4     
========================================
+ Hits        49475    49504    +29     
- Misses       8947     9462   +515     
+ Partials     1385      869   -516     
Flag Coverage Δ
23.11.6 7.30% <0.00%> (+0.02%) ⬆️
24.11.5 7.31% <0.00%> (+<0.01%) ⬆️
25.11.1 7.32% <0.00%> (+<0.01%) ⬆️
alpine320 76.86% <100.00%> (+<0.01%) ⬆️
fedora42 76.45% <100.00%> (+0.01%) ⬆️
macos-14 82.26% <89.28%> (-0.01%) ⬇️
macos-15 82.26% <89.28%> (+<0.01%) ⬆️
mingw32 71.13% <100.00%> (+0.01%) ⬆️
mingw64 71.10% <100.00%> (+0.08%) ⬆️
npcap ?
rhel94 76.28% <100.00%> (+0.03%) ⬆️
ubuntu2204 76.27% <100.00%> (+<0.01%) ⬆️
ubuntu2204-icpx 59.38% <100.00%> (-0.03%) ⬇️
ubuntu2404 76.56% <100.00%> (-0.02%) ⬇️
ubuntu2404-arm64 76.57% <100.00%> (+0.01%) ⬆️
ubuntu2604 76.48% <100.00%> (-0.03%) ⬇️
unittest 82.73% <100.00%> (+<0.01%) ⬆️
windows-2022 85.81% <100.00%> (+0.11%) ⬆️
windows-2025 85.83% <100.00%> (+0.13%) ⬆️
winpcap 85.83% <100.00%> (-0.07%) ⬇️
xdp 53.17% <100.00%> (+0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@Dimi1010 Dimi1010 marked this pull request as ready for review May 23, 2026 05:10
@Dimi1010 Dimi1010 requested a review from seladb as a code owner May 23, 2026 05:10
Comment thread Packet++/header/Layer.h
/// @param[out] dest The destination byte array
/// @param[in] destSize The maximum number of bytes to copy
/// @return The number of bytes copied to the destination array.
size_t copyData(uint8_t* dest, size_t destSize) const;

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Can we add tests for this new method?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Added ba39b93

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Perhaps we should add it in PacketTests.cpp?
We already have CopyLayerAndPacketTest that kind of fits, or we can add another test in this file

@Dimi1010 Dimi1010 May 30, 2026

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Moved the test to PacketTests.cpp 9f5e360
Kept the test separate because Ctrl+C, Ctrl+V was easier and CopyLayerAndPacketTest is very large as is.

@Dimi1010 Dimi1010 requested a review from seladb May 25, 2026 09:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants