Browse Source

Add `accounts.is_empty()` check (#1697)

Samuel Moelius 3 years ago
parent
commit
27c3513dfc
1 changed files with 3 additions and 0 deletions
  1. 3 0
      lang/syn/src/codegen/accounts/try_accounts.rs

+ 3 - 0
lang/syn/src/codegen/accounts/try_accounts.rs

@@ -35,6 +35,9 @@ pub fn generate(accs: &AccountsStruct) -> proc_macro2::TokenStream {
                     if is_init(af) || f.constraints.zeroed.is_some() {
                     if is_init(af) || f.constraints.zeroed.is_some() {
                         let name = &f.ident;
                         let name = &f.ident;
                         quote!{
                         quote!{
+                            if accounts.is_empty() {
+                                return Err(anchor_lang::error::ErrorCode::AccountNotEnoughKeys.into());
+                            }
                             let #name = &accounts[0];
                             let #name = &accounts[0];
                             *accounts = &accounts[1..];
                             *accounts = &accounts[1..];
                         }
                         }