Skip to content

Commit

Permalink
lang: Check that ProgramAccount writable on deref_mut (#681)
Browse files Browse the repository at this point in the history
  • Loading branch information
fanatid committed Sep 7, 2021
1 parent 3f6af1f commit 675c7cd
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ incremented for features.

## [Unreleased]

### Features

* lang: Check that ProgramAccount writable before mut borrow (`anchor-debug` only) ([#681](https://github.com/project-serum/anchor/pull/681)).

## [0.14.0] - 2021-09-02

### Features
Expand Down
6 changes: 6 additions & 0 deletions lang/src/program_account.rs
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,12 @@ impl<'a, T: AccountSerialize + AccountDeserialize + Clone> Deref for ProgramAcco

impl<'a, T: AccountSerialize + AccountDeserialize + Clone> DerefMut for ProgramAccount<'a, T> {
fn deref_mut(&mut self) -> &mut Self::Target {
#[cfg(feature = "anchor-debug")]
if !self.inner.info.is_writable {
solana_program::msg!("The given ProgramAccount is not mutable");
panic!();
}

&mut DerefMut::deref_mut(&mut self.inner).account
}
}
Expand Down

0 comments on commit 675c7cd

Please sign in to comment.