From 12399157f56a36d25dca5b8260d0e3713b6f4105 Mon Sep 17 00:00:00 2001 From: Trent Nelson Date: Tue, 16 Feb 2021 14:40:49 -0700 Subject: [PATCH] SDK: Allow integer math in bump allocator --- sdk/program/src/entrypoint.rs | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/sdk/program/src/entrypoint.rs b/sdk/program/src/entrypoint.rs index dc8f1e216d..6bebaa9b6c 100644 --- a/sdk/program/src/entrypoint.rs +++ b/sdk/program/src/entrypoint.rs @@ -1,4 +1,3 @@ -#![allow(clippy::integer_arithmetic)] //! @brief Solana Rust-based BPF program entry point supported by the latest //! BPFLoader. For more information see './bpf_loader.rs' @@ -104,6 +103,10 @@ pub struct BumpAllocator { pub start: usize, pub len: usize, } +/// Integer arithmetic in this global allocator implementation is safe when +/// operating on the prescribed `HEAP_START_ADDRESS` and `HEAP_LENGTH`. Any +/// other use may overflow and is thus unsupported and at one's own risk. +#[allow(clippy::integer_arithmetic)] unsafe impl std::alloc::GlobalAlloc for BumpAllocator { #[inline] unsafe fn alloc(&self, layout: Layout) -> *mut u8 { @@ -133,6 +136,11 @@ pub const MAX_PERMITTED_DATA_INCREASE: usize = 1_024 * 10; /// Deserialize the input arguments /// +/// The integer arithmetic in this method is safe when called on a buffer that was +/// serialized by runtime. Use with buffers serialized otherwise is unsupported and +/// done at one's own risk. +#[allow(clippy::integer_arithmetic)] +/// /// # Safety #[allow(clippy::type_complexity)] pub unsafe fn deserialize<'a>(input: *mut u8) -> (&'a Pubkey, Vec>, &'a [u8]) {