From 821e33705e0c7b252daf50d320fbef7ef78ddc42 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ot=C3=A1vio=20Pace?= Date: Wed, 8 Sep 2021 20:40:40 -0300 Subject: [PATCH] runtime: Make size_of_rt_size a constant --- graph/src/runtime/asc_ptr.rs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/graph/src/runtime/asc_ptr.rs b/graph/src/runtime/asc_ptr.rs index 0b3f939769d..d2318cfb09b 100644 --- a/graph/src/runtime/asc_ptr.rs +++ b/graph/src/runtime/asc_ptr.rs @@ -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(u32, PhantomData); @@ -154,8 +157,7 @@ impl AscPtr { // 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::() as u32)?;