Skip to content

Commit 8ae81a5

Browse files
authored
Fix Clippy lints (#37)
* Fix underconstrained type on `nx::sf::Buffer`. The buffer type previously didn't take into account the lifetime of the referenced data, so it is easy to cause use after free in API clients or accidentally hold on to buffer references too long in server implementations. This gives a lifetime bound to the buffer type so it (hopefully) doesn't outlive the source data or escape the server function. * Fix clippy lints
1 parent d1f3f1c commit 8ae81a5

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

src/ipc/sf.rs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,12 @@ impl<
5858

5959
// TODO: ensure that sizeof(T) is a multiple of size
6060

61+
/// Creates a `Buffer` from raw parts
62+
///
63+
/// # Safety
64+
///
65+
/// It is the caller's responsibility to ensure the lifetime of the buffer does not exceed the
66+
/// inner data.
6167
pub const unsafe fn new<'a: 'borrow>(addr: *mut u8, size: usize) -> Self {
6268
Self {
6369
buf: addr as *mut T,
@@ -66,6 +72,12 @@ impl<
6672
}
6773
}
6874

75+
/// Creates a `Buffer` from a raw pointer
76+
///
77+
/// # Safety
78+
///
79+
/// It is the caller's responsibility to ensure the lifetime of the buffer does not exceed the
80+
/// inner data.
6981
pub const unsafe fn from_ptr<'a: 'borrow>(buf: *const T, count: usize) -> Self {
7082
Self {
7183
buf: buf as *mut T,
@@ -74,6 +86,12 @@ impl<
7486
}
7587
}
7688

89+
/// Creates a `Buffer` from a raw pointer
90+
///
91+
/// # Safety
92+
///
93+
/// It is the caller's responsibility to ensure the lifetime of the buffer does not exceed the
94+
/// inner data.
7795
pub const unsafe fn from_mut_ptr<'a: 'borrow>(buf: *mut T, count: usize) -> Self {
7896
Self {
7997
buf,

src/rrt0.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -295,7 +295,7 @@ unsafe fn normal_entry(loader_mode: LoaderMode, exit_config: Option<ExitFn>) ->
295295
// Initialize version support
296296
initialize_version(hos_version_opt);
297297

298-
let res = unsafe { main() };
298+
unsafe { main() };
299299

300300
// unmount fs devices
301301
#[cfg(feature = "fs")]

0 commit comments

Comments
 (0)