Fix boundary condition in skip method #113
Open
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This update addresses a critical boundary condition issue in the
skip
method of theSource
implementation for(Arc<Vec<G>>, usize)
.What was the issue?
Previously, the check for sufficient elements in the vector was incorrectly written as:
This condition only ensured that the current index
self.1
was within bounds but did not account for the additionalamt
elements being skipped. As a result, ifamt
was large enough, the resulting index (self.1 + amt
) could exceed the vector's length, leading to undefined behavior or runtime panics when accessing elements out of bounds.What has been changed?
The condition has been updated to:
This guarantees that the entire range
[self.1, self.1 + amt)
lies within the bounds of the vector, preventing invalid memory access.Why is this important?
amt
in theskip
method.amt
elements, only if they exist.This change is critical for anyone relying on this functionality, especially in production scenarios involving complex computations or parallelism.