Skip to content
This repository was archived by the owner on Mar 11, 2025. It is now read-only.

Commit 7b5eb2a

Browse files
authored
Fix account size comparisons (#359)
1 parent dc8dcc0 commit 7b5eb2a

File tree

3 files changed

+306
-106
lines changed

3 files changed

+306
-106
lines changed

token/program/src/pack.rs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,11 @@ pub trait Pack: Sealed {
2121
#[doc(hidden)]
2222
fn unpack_from_slice(src: &[u8]) -> Result<Self, ProgramError>;
2323

24+
/// Get the packed length
25+
fn get_packed_len() -> usize {
26+
Self::LEN
27+
}
28+
2429
/// Unpack from slice and check if initialized
2530
fn unpack(input: &[u8]) -> Result<Self, ProgramError>
2631
where
@@ -36,8 +41,7 @@ pub trait Pack: Sealed {
3641

3742
/// Unpack from slice without checking if initialized
3843
fn unpack_unchecked(input: &[u8]) -> Result<Self, ProgramError> {
39-
if input.len() < Self::LEN {
40-
println!("ilen {:?} tlen {:?}", input.len(), Self::LEN);
44+
if input.len() != Self::LEN {
4145
return Err(ProgramError::InvalidAccountData);
4246
}
4347
Ok(Self::unpack_from_slice(input)?)
@@ -72,8 +76,7 @@ pub trait Pack: Sealed {
7276

7377
/// Pack into slice
7478
fn pack(src: Self, dst: &mut [u8]) -> Result<(), ProgramError> {
75-
if dst.len() < Self::LEN {
76-
println!("dlen {:?} tlen {:?}", dst.len(), Self::LEN);
79+
if dst.len() != Self::LEN {
7780
return Err(ProgramError::InvalidAccountData);
7881
}
7982
src.pack_into_slice(dst);

0 commit comments

Comments
 (0)