Skip to content

Commit

Permalink
runtime: Make size_of_rt_size a constant
Browse files Browse the repository at this point in the history
  • Loading branch information
evaporei committed Sep 8, 2021
1 parent d03ddb0 commit 821e337
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions graph/src/runtime/asc_ptr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ use std::fmt;
use std::marker::PhantomData;
use std::mem::size_of;

/// The `rt_size` field contained in an AssemblyScript header has a size of 4 bytes.
const SIZE_OF_RT_SIZE: u32 = 4;

/// A pointer to an object in the Asc heap.
pub struct AscPtr<C>(u32, PhantomData<C>);

Expand Down Expand Up @@ -154,8 +157,7 @@ impl<C: AscType> AscPtr<C> {
// not null before using it.
self.check_is_not_null()?;

let size_of_rt_size = 4;
let start_of_rt_size = self.0.checked_sub(size_of_rt_size).ok_or_else(|| {
let start_of_rt_size = self.0.checked_sub(SIZE_OF_RT_SIZE).ok_or_else(|| {
DeterministicHostError(anyhow::anyhow!("Subtract overflow on pointer: {}", self.0))
})?;
let raw_bytes = heap.get(start_of_rt_size, size_of::<u32>() as u32)?;
Expand Down

0 comments on commit 821e337

Please sign in to comment.