Skip to content

Commit

Permalink
Add missing #![deny(unsafe_op_in_unsafe_fn)] to upb/rust/lib.rs and f…
Browse files Browse the repository at this point in the history
…ix violating functions

PiperOrigin-RevId: 655226304
  • Loading branch information
dbenson24 authored and copybara-github committed Jul 23, 2024
1 parent 607b4b1 commit 41f12a2
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
2 changes: 2 additions & 0 deletions rust/upb/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file or at
// https://developers.google.com/open-source/licenses/bsd
#![deny(unsafe_op_in_unsafe_fn)]

mod arena;

pub use arena::{upb_Arena, Arena, RawArena};

mod array;
Expand Down
7 changes: 4 additions & 3 deletions rust/upb/wire.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,12 +56,12 @@ pub unsafe fn encode(
// SAFETY:
// - `mini_table` is the one associated with `msg`.
// - `buf` and `buf_size` are legally writable.
let status = upb_Encode(msg, mini_table, 0, arena.raw(), &mut buf, &mut len);
let status = unsafe { upb_Encode(msg, mini_table, 0, arena.raw(), &mut buf, &mut len) };

if status == EncodeStatus::Ok {
assert!(!buf.is_null()); // EncodeStatus Ok should never return NULL data, even for len=0.
// SAFETY: upb guarantees that `buf` is valid to read for `len`.
Ok((*std::ptr::slice_from_raw_parts(buf, len)).to_vec())
Ok(unsafe { &*std::ptr::slice_from_raw_parts(buf, len) }.to_vec())
} else {
Err(status)
}
Expand All @@ -87,7 +87,8 @@ pub unsafe fn decode(
// - `mini_table` is the one associated with `msg`
// - `buf` is legally readable for at least `buf_size` bytes.
// - `extreg` is null.
let status = upb_Decode(buf, len, msg, mini_table, std::ptr::null(), options, arena.raw());
let status =
unsafe { upb_Decode(buf, len, msg, mini_table, std::ptr::null(), options, arena.raw()) };
match status {
DecodeStatus::Ok => Ok(()),
_ => Err(status),
Expand Down

0 comments on commit 41f12a2

Please sign in to comment.