Add missing #![deny(unsafe_op_in_unsafe_fn)] to upb/rust/lib.rs and fix violating functions

PiperOrigin-RevId: 655226304
pull/17575/head
Derek Benson 9 months ago committed by Copybara-Service
parent 607b4b1b6c
commit 41f12a239c
  1. 2
      rust/upb/lib.rs
  2. 7
      rust/upb/wire.rs

@ -4,8 +4,10 @@
// Use of this source code is governed by a BSD-style // Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file or at // license that can be found in the LICENSE file or at
// https://developers.google.com/open-source/licenses/bsd // https://developers.google.com/open-source/licenses/bsd
#![deny(unsafe_op_in_unsafe_fn)]
mod arena; mod arena;
pub use arena::{upb_Arena, Arena, RawArena}; pub use arena::{upb_Arena, Arena, RawArena};
mod array; mod array;

@ -56,12 +56,12 @@ pub unsafe fn encode(
// SAFETY: // SAFETY:
// - `mini_table` is the one associated with `msg`. // - `mini_table` is the one associated with `msg`.
// - `buf` and `buf_size` are legally writable. // - `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 { if status == EncodeStatus::Ok {
assert!(!buf.is_null()); // EncodeStatus Ok should never return NULL data, even for len=0. 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`. // 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 { } else {
Err(status) Err(status)
} }
@ -87,7 +87,8 @@ pub unsafe fn decode(
// - `mini_table` is the one associated with `msg` // - `mini_table` is the one associated with `msg`
// - `buf` is legally readable for at least `buf_size` bytes. // - `buf` is legally readable for at least `buf_size` bytes.
// - `extreg` is null. // - `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 { match status {
DecodeStatus::Ok => Ok(()), DecodeStatus::Ok => Ok(()),
_ => Err(status), _ => Err(status),

Loading…
Cancel
Save