-
Notifications
You must be signed in to change notification settings - Fork 9
fix: replace size compute #204
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
CodSpeed Performance ReportMerging #204 will improve performances by ×5Comparing Summary
Benchmarks breakdown
Footnotes
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR fixes a bug in the size() method of ReplaceSource where replacements that start beyond the source bounds were causing incorrect size calculations. The fix adds an early check to handle out-of-bounds replacements by simply adding their content length to the total size.
Key Changes:
- Added a boundary check in the
size()method to detect and handle replacements that start beyond the inner source size - Added a test case with an out-of-bounds replacement to verify the fix works correctly
Comments suppressed due to low confidence (1)
src/replace_source.rs:223
- The current fix handles replacements that start entirely beyond the source bounds, but it doesn't handle the case where a replacement starts within bounds but extends beyond them (i.e.,
replacement.start < inner_source_sizebutreplacement.end > inner_source_size).
For example, if the source is 1070 bytes and we have a replacement from position 1000 to 2000, the current code calculates:
original_length = 2000 - 1000 = 1000(line 220-223)- But the actual original content is only 70 bytes (from 1000 to 1070)
This causes the size calculation to be incorrect because it subtracts the full 1000 bytes instead of just 70 bytes.
Consider clamping the replacement.end to inner_source_size when calculating original_length:
let original_length = replacement
.end
.min(inner_source_size as u32) // Clamp to source size
.saturating_sub(replacement.start.max(inner_pos))
as usize; let original_length = replacement
.end
.saturating_sub(replacement.start.max(inner_pos))
as usize;
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
083552b to
3d48556
Compare
3d48556 to
045e2c0
Compare
68d17f6 to
23ac553
Compare
e1330cf to
fec461e
Compare
536b2e8 to
ef71210
Compare
09171a9 to
c90f574
Compare
8b8798f to
f10038d
Compare
f10038d to
118f6ea
Compare
79be155 to
62de843
Compare
d1f7d73 to
22c07eb
Compare
2be9e2c to
adcbd42
Compare
adcbd42 to
9b5beab
Compare
7220862 to
3c1808d
Compare
No description provided.