-
Notifications
You must be signed in to change notification settings - Fork 13.8k
Refactor module mount load in rust #8846
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
Open
yujincheng08
wants to merge
1
commit into
master
Choose a base branch
from
module.rs
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -81,6 +81,9 @@ pub trait Utf8CStrBuf: | |||||||||||||||||||||||||||
// 2. Ensure len <= capacity - 1 | ||||||||||||||||||||||||||||
// 3. All bytes from 0 to len is valid UTF-8 and does not contain null | ||||||||||||||||||||||||||||
unsafe fn set_len(&mut self, len: usize); | ||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||
// self[len] = b'\0'; self.set_len(len) | ||||||||||||||||||||||||||||
fn resize(&mut self, len: usize); | ||||||||||||||||||||||||||||
fn push_str(&mut self, s: &str) -> usize; | ||||||||||||||||||||||||||||
fn push_lossy(&mut self, s: &[u8]) -> usize; | ||||||||||||||||||||||||||||
// The capacity of the internal buffer. The maximum string length this buffer can contain | ||||||||||||||||||||||||||||
|
@@ -185,6 +188,7 @@ impl StringExt for PathBuf { | |||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||
#[derive(Eq, Ord, PartialOrd)] | ||||||||||||||||||||||||||||
pub struct Utf8CString(String); | ||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||
impl Default for Utf8CString { | ||||||||||||||||||||||||||||
|
@@ -236,6 +240,16 @@ impl Utf8CStrBuf for Utf8CString { | |||||||||||||||||||||||||||
self.0.as_mut_vec().set_len(len); | ||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||
fn resize(&mut self, len: usize) { | ||||||||||||||||||||||||||||
if len >= self.0.capacity() { | ||||||||||||||||||||||||||||
return; | ||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||
unsafe { | ||||||||||||||||||||||||||||
*self.0.as_mut_ptr().add(len) = b'\0' as _; | ||||||||||||||||||||||||||||
self.set_len(len); | ||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||
fn push_str(&mut self, s: &str) -> usize { | ||||||||||||||||||||||||||||
self.0.push_str(s); | ||||||||||||||||||||||||||||
|
@@ -583,6 +597,14 @@ impl<const N: usize> FsPathBuf<N> { | |||||||||||||||||||||||||||
inner(self.0.deref_mut(), path.as_ref()); | ||||||||||||||||||||||||||||
self | ||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||
pub fn resize(mut self, len: usize) -> Self { | ||||||||||||||||||||||||||||
unsafe { | ||||||||||||||||||||||||||||
self.0.as_bytes_mut()[len] = b'\0'; | ||||||||||||||||||||||||||||
self.0.set_len(len) | ||||||||||||||||||||||||||||
}; | ||||||||||||||||||||||||||||
Comment on lines
+602
to
+605
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The FsPathBuf resize method lacks a bounds check on the provided len, which may lead to out-of-bound access. Consider adding a check to ensure len is within the valid range.
Suggested change
Copilot uses AI. Check for mistakes. Positive FeedbackNegative Feedback |
||||||||||||||||||||||||||||
self | ||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||
pub fn join_fmt<T: Display>(mut self, name: T) -> Self { | ||||||||||||||||||||||||||||
self.0.write_fmt(format_args!("/{}", name)).ok(); | ||||||||||||||||||||||||||||
|
@@ -742,6 +764,14 @@ macro_rules! impl_str_buf_with_slice { | |||||||||||||||||||||||||||
unsafe fn set_len(&mut self, len: usize) { | ||||||||||||||||||||||||||||
self.used = len; | ||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||
fn resize(&mut self, len: usize) { | ||||||||||||||||||||||||||||
if len < self.capacity() { | ||||||||||||||||||||||||||||
unsafe { | ||||||||||||||||||||||||||||
self.buf[len] = b'\0'; | ||||||||||||||||||||||||||||
self.set_len(len); | ||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||
#[inline(always)] | ||||||||||||||||||||||||||||
fn push_str(&mut self, s: &str) -> usize { | ||||||||||||||||||||||||||||
utf8_cstr_buf_append(self, s.as_bytes()) | ||||||||||||||||||||||||||||
|
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
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
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
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
Oops, something went wrong.
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.
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.
The Utf8CString resize method silently returns if len is greater than or equal to capacity. It might be better to handle this case explicitly (e.g., by returning a Result or panicking) to avoid unintended behavior.
Copilot uses AI. Check for mistakes.