Replace unsafe get_unchecked_mut with safe indexing in insert_score_depth and insert_score#169
Merged
chase-manning merged 4 commits intomainfrom Feb 22, 2026
Merged
Conversation
Co-authored-by: chase-manning <53957795+chase-manning@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Fix unsound problems in pleco_engine crate
Add bounds checking to Feb 22, 2026
insert_score_depth and insert_score in RootMoveList
Contributor
|
@copilot linting ci broken |
Co-authored-by: chase-manning <53957795+chase-manning@users.noreply.github.com>
Contributor
Author
Contributor
|
@copilot resolve merge conflicts |
…hecked_mut Co-authored-by: chase-manning <53957795+chase-manning@users.noreply.github.com>
Contributor
Author
Copilot
AI
changed the title
Add bounds checking to
Replace unsafe Feb 22, 2026
insert_score_depth and insert_score in RootMoveListget_unchecked_mut with safe indexing in insert_score_depth and insert_score
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
insert_score_depthandinsert_scoreare public functions that previously usedget_unchecked_mutwithout validating the caller-provided index, making them unsound — callers could trigger undefined behavior with an out-of-bounds index.Changes Made
unsafe { self.get_unchecked_mut(index) }with safe&mut self[index]indexing in bothinsert_score_depthandinsert_score. This leverages the existingIndexMutimplementation, which goes throughDerefMutand slice indexing to automatically provide bounds checking and panic on invalid indices.#[should_panic]tests to verify that out-of-bounds access correctly panics for both functions.This removes the
unsafeblocks entirely while preserving the same public API and behavior for valid inputs.Original prompt
pleco_enginecrate #158✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.