Skip to content

Commit

Permalink
Add missing SAFETY docs
Browse files Browse the repository at this point in the history
  • Loading branch information
Jake-Shadle committed Aug 9, 2024
1 parent ce7d41f commit 6305b23
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/components/proxy/io_uring_shared.rs
Original file line number Diff line number Diff line change
Expand Up @@ -465,6 +465,8 @@ impl<'uring> LoopCtx<'uring> {
self.sq.sync();

match self.backlog.pop_front() {
// SAFETY: Same as Self::push, all memory pointed to in our ops are pinned at
// stable locations in memory
Some(sqe) => unsafe {
let _ = self.sq.push(&sqe);
},
Expand Down
1 change: 1 addition & 0 deletions src/components/proxy/sessions/inner_metrics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ pub(crate) fn active_sessions(asn: Option<&crate::net::maxmind_db::IpNetEntry>)
let len = crate::metrics::itoa(asnfo.id, &mut asn);

ACTIVE_SESSIONS.with_label_values(&[
// SAFETY: itoa only writes ASCII
unsafe { std::str::from_utf8_unchecked(&asn[..len as _]) },
&asnfo.as_name,
&asnfo.as_cc,
Expand Down
1 change: 1 addition & 0 deletions src/metrics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ pub struct AsnInfo<'a> {
impl<'a> AsnInfo<'a> {
#[inline]
fn asn_str(&self) -> &str {
// SAFETY: we only write ASCII in itoa
unsafe { std::str::from_utf8_unchecked(&self.asn[..self.asn_len as _]) }
}
}
Expand Down
2 changes: 2 additions & 0 deletions src/pool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,8 @@ impl PoolBuffer {
#[inline]
#[cfg(target_os = "linux")]
pub(crate) fn set_len(&mut self, len: usize) {
// SAFETY: len is the length as returned from the kernel on a successful
// recv_from call
unsafe { self.inner.set_len(len) }
}
}
Expand Down

0 comments on commit 6305b23

Please sign in to comment.