Skip to content

Commit

Permalink
proxy: remove unsafe (#5805)
Browse files Browse the repository at this point in the history
## Problem

`unsafe {}`

## Summary of changes

`CStr` has a method to parse the bytes up to a null byte, so we don't
have to do it ourselves.
  • Loading branch information
conradludgate committed Nov 6, 2023
1 parent b09a851 commit ad5b02e
Showing 1 changed file with 3 additions and 4 deletions.
7 changes: 3 additions & 4 deletions proxy/src/parse.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,9 @@
use std::ffi::CStr;

pub fn split_cstr(bytes: &[u8]) -> Option<(&CStr, &[u8])> {
let pos = bytes.iter().position(|&x| x == 0)?;
let (cstr, other) = bytes.split_at(pos + 1);
// SAFETY: we've already checked that there's a terminator
Some((unsafe { CStr::from_bytes_with_nul_unchecked(cstr) }, other))
let cstr = CStr::from_bytes_until_nul(bytes).ok()?;
let (_, other) = bytes.split_at(cstr.to_bytes_with_nul().len());
Some((cstr, other))
}

/// See <https://doc.rust-lang.org/std/primitive.slice.html#method.split_array_ref>.
Expand Down

1 comment on commit ad5b02e

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

2426 tests run: 2303 passed, 1 failed, 122 skipped (full report)


Failures on Postgres 15

  • test_timeline_resurrection_on_attach[False-mock_s3]: release
# Run all failed tests locally:
scripts/pytest -vv -n $(nproc) -k "test_timeline_resurrection_on_attach[release-pg15-False-mock_s3]"
Flaky tests (1)

Postgres 16

Test coverage report is not available

The comment gets automatically updated with the latest test results
ad5b02e at 2023-11-06T18:26:18.048Z :recycle:

Please sign in to comment.