Skip to content
This repository has been archived by the owner on Jan 13, 2025. It is now read-only.

Commit

Permalink
Align C and Rust handling of AccountInfos (#8906)
Browse files Browse the repository at this point in the history
  • Loading branch information
jackcmay authored Mar 17, 2020
1 parent 61514e3 commit 668dfc4
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 3 deletions.
2 changes: 1 addition & 1 deletion programs/bpf/c/src/error_handling/error_handling.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
*/

extern uint64_t entrypoint(const uint8_t *input) {
SolKeyedAccount ka[4];
SolKeyedAccount ka[1];
SolParameters params = (SolParameters) { .ka = ka };

if (!sol_deserialize(input, &params, SOL_ARRAY_SIZE(ka))) {
Expand Down
19 changes: 17 additions & 2 deletions sdk/bpf/c/inc/solana_sdk.h
Original file line number Diff line number Diff line change
Expand Up @@ -284,13 +284,29 @@ SOL_FN_PREFIX bool sol_deserialize(
}
params->ka_num = *(uint64_t *) input;
input += sizeof(uint64_t);
if (ka_num < params->ka_num) {

if (ka_num > params->ka_num) {
return false;
}

for (int i = 0; i < params->ka_num; i++) {
uint8_t dup_info = input[0];
input += sizeof(uint8_t);

if (i >= ka_num) {
if (dup_info == UINT8_MAX) {
input += sizeof(uint8_t);
input += sizeof(uint8_t);
input += sizeof(SolPubkey);
input += sizeof(uint64_t);
input += *(uint64_t *) input;
input += sizeof(uint64_t);
input += sizeof(SolPubkey);
input += sizeof(uint8_t);
input += sizeof(uint64_t);
}
continue;
}
if (dup_info == UINT8_MAX) {
// is signer?
params->ka[i].is_signer = *(uint8_t *) input != 0;
Expand Down Expand Up @@ -418,7 +434,6 @@ SOL_FN_PREFIX void sol_log_params(const SolParameters *params) {
*/
uint64_t entrypoint(const uint8_t *input);


#ifdef SOL_TEST
/**
* Stub log functions when building tests
Expand Down

0 comments on commit 668dfc4

Please sign in to comment.