From 71d6eaacef8b45362678f8cfa4e590c1fdbb0298 Mon Sep 17 00:00:00 2001 From: Michael Vines Date: Mon, 29 Oct 2018 19:56:24 -0700 Subject: [PATCH] Apply some const --- programs/bpf/c/sdk/inc/sol_bpf_c.h | 22 +++++++++++----------- programs/bpf/c/src/move_funds.c | 6 +++--- programs/bpf/c/src/noop.c | 6 +++--- programs/bpf/c/src/tictactoe.c | 6 +++--- programs/bpf/c/src/tictactoe_dashboard.c | 6 +++--- 5 files changed, 23 insertions(+), 23 deletions(-) diff --git a/programs/bpf/c/sdk/inc/sol_bpf_c.h b/programs/bpf/c/sdk/inc/sol_bpf_c.h index 9f5cbb29a..a2cb2ef72 100644 --- a/programs/bpf/c/sdk/inc/sol_bpf_c.h +++ b/programs/bpf/c/sdk/inc/sol_bpf_c.h @@ -75,7 +75,7 @@ typedef struct { * @param two Second public key * @return True if the same */ -SOL_FN_PREFIX bool SolPubkey_same(SolPubkey *one, SolPubkey *two) { +SOL_FN_PREFIX bool SolPubkey_same(const SolPubkey *one, const SolPubkey *two) { for (int i = 0; i < SIZE_PUBKEY; i++) { if (one->x[i] != two->x[i]) { return false; @@ -98,9 +98,9 @@ typedef struct { /** * Copies memory */ -SOL_FN_PREFIX void sol_memcpy(void *dst, void *src, int len) { +SOL_FN_PREFIX void sol_memcpy(void *dst, const void *src, int len) { for (int i = 0; i < len; i++) { - *((uint8_t *)dst + i) = *((uint8_t *)src + i); + *((uint8_t *)dst + i) = *((const uint8_t *)src + i); } } @@ -142,7 +142,7 @@ SOL_FN_PREFIX void _sol_panic(uint64_t line) { * @param data_len On return, the length in bytes of the instruction data * @return Boolan True if successful */ -SOL_FN_PREFIX bool sol_deserialize(uint8_t *input, uint64_t num_ka, +SOL_FN_PREFIX bool sol_deserialize(const uint8_t *input, uint64_t num_ka, SolKeyedAccounts *ka, uint8_t **data, uint64_t *data_len) { if (num_ka != *(uint64_t *)input) { @@ -187,7 +187,7 @@ SOL_FN_PREFIX bool sol_deserialize(uint8_t *input, uint64_t num_ka, * * @param key The public key to print */ -SOL_FN_PREFIX void sol_print_key(SolPubkey *key) { +SOL_FN_PREFIX void sol_print_key(const SolPubkey *key) { for (int j = 0; j < SIZE_PUBKEY; j++) { sol_print(0, 0, 0, j, key->x[j]); } @@ -198,7 +198,7 @@ SOL_FN_PREFIX void sol_print_key(SolPubkey *key) { * * @param array The array to print */ -SOL_FN_PREFIX void sol_print_array(uint8_t *array, int len) { +SOL_FN_PREFIX void sol_print_array(const uint8_t *array, int len) { for (int j = 0; j < len; j++) { sol_print(0, 0, 0, j, array[j]); } @@ -212,8 +212,8 @@ SOL_FN_PREFIX void sol_print_array(uint8_t *array, int len) { * @param data A pointer to the instruction data to print * @param data_len The length in bytes of the instruction data */ -SOL_FN_PREFIX void sol_print_params(uint64_t num_ka, SolKeyedAccounts *ka, - uint8_t *data, uint64_t data_len) { +SOL_FN_PREFIX void sol_print_params(uint64_t num_ka, const SolKeyedAccounts *ka, + const uint8_t *data, uint64_t data_len) { sol_print(0, 0, 0, 0, num_ka); for (int i = 0; i < num_ka; i++) { sol_print_key(ka[i].key); @@ -235,12 +235,12 @@ SOL_FN_PREFIX void sol_print_params(uint64_t num_ka, SolKeyedAccounts *ka, * * #define NUM_KA 1 * - * bool entrypoint(uint8_t *input) { + * bool entrypoint(const uint8_t *input) { * SolKeyedAccounts ka[NUM_KA]; * uint8_t *data; * uint64_t data_len; * - * if (1 != sol_deserialize((uint8_t *)buf, NUM_KA, ka, &data, &data_len)) { + * if (1 != sol_deserialize(buf, NUM_KA, ka, &data, &data_len)) { * return false; * } * print_params(1, ka, data, data_len); @@ -254,7 +254,7 @@ SOL_FN_PREFIX void sol_print_params(uint64_t num_ka, SolKeyedAccounts *ka, * @param input An array containing serialized input parameters * @return True if successful */ -extern bool entrypoint(uint8_t *input); +extern bool entrypoint(const uint8_t *input); /**@}*/ diff --git a/programs/bpf/c/src/move_funds.c b/programs/bpf/c/src/move_funds.c index 2f3517112..c982d18dd 100644 --- a/programs/bpf/c/src/move_funds.c +++ b/programs/bpf/c/src/move_funds.c @@ -6,17 +6,17 @@ #include /** - * Numer of SolKeyedAccounts expected. The program should bail if an + * Number of SolKeyedAccounts expected. The program should bail if an * unexpected number of accounts are passed to the program's entrypoint */ #define NUM_KA 3 -extern bool entrypoint(uint8_t *input) { +extern bool entrypoint(const uint8_t *input) { SolKeyedAccounts ka[NUM_KA]; uint8_t *data; uint64_t data_len; - if (!sol_deserialize((uint8_t *)input, NUM_KA, ka, &data, &data_len)) { + if (!sol_deserialize(input, NUM_KA, ka, &data, &data_len)) { return false; } diff --git a/programs/bpf/c/src/noop.c b/programs/bpf/c/src/noop.c index 5662aab3c..cd24f1a39 100644 --- a/programs/bpf/c/src/noop.c +++ b/programs/bpf/c/src/noop.c @@ -6,17 +6,17 @@ #include /** - * Numer of SolKeyedAccounts expected. The program should bail if an + * Number of SolKeyedAccounts expected. The program should bail if an * unexpected number of accounts are passed to the program's entrypoint */ #define NUM_KA 1 -extern bool entrypoint(uint8_t *input) { +extern bool entrypoint(const uint8_t *input) { SolKeyedAccounts ka[NUM_KA]; uint8_t *data; uint64_t data_len; - if (!sol_deserialize((uint8_t *)input, NUM_KA, ka, &data, &data_len)) { + if (!sol_deserialize(input, NUM_KA, ka, &data, &data_len)) { return false; } sol_print_params(1, ka, data, data_len); diff --git a/programs/bpf/c/src/tictactoe.c b/programs/bpf/c/src/tictactoe.c index af9311d44..083d31ca0 100644 --- a/programs/bpf/c/src/tictactoe.c +++ b/programs/bpf/c/src/tictactoe.c @@ -173,7 +173,7 @@ SOL_FN_PREFIX Result game_keep_alive(Game *self, SolPubkey *player, } /** - * Numer of SolKeyedAccounts expected. The program should bail if an + * Number of SolKeyedAccounts expected. The program should bail if an * unexpected number of accounts are passed to the program's entrypoint * * accounts[0] On Init must be player X, after that doesn't matter, @@ -183,13 +183,13 @@ SOL_FN_PREFIX Result game_keep_alive(Game *self, SolPubkey *player, */ #define NUM_KA 3 -extern bool entrypoint(uint8_t *input) { +extern bool entrypoint(const uint8_t *input) { SolKeyedAccounts ka[NUM_KA]; uint8_t *data; uint64_t data_len; int err = 0; - if (!sol_deserialize((uint8_t *)input, NUM_KA, ka, &data, &data_len)) { + if (!sol_deserialize(input, NUM_KA, ka, &data, &data_len)) { return false; } diff --git a/programs/bpf/c/src/tictactoe_dashboard.c b/programs/bpf/c/src/tictactoe_dashboard.c index 789276b99..cacfcf4fa 100644 --- a/programs/bpf/c/src/tictactoe_dashboard.c +++ b/programs/bpf/c/src/tictactoe_dashboard.c @@ -54,7 +54,7 @@ SOL_FN_PREFIX bool update(Dashboard *self, Game *game, SolPubkey *game_pubkey) { } /** - * Numer of SolKeyedAccounts expected. The program should bail if an + * Number of SolKeyedAccounts expected. The program should bail if an * unexpected number of accounts are passed to the program's entrypoint * * accounts[0] doesn't matter, anybody can cause a dashboard update @@ -63,13 +63,13 @@ SOL_FN_PREFIX bool update(Dashboard *self, Game *game, SolPubkey *game_pubkey) { */ #define NUM_KA 3 -extern bool entrypoint(uint8_t *input) { +extern bool entrypoint(const uint8_t *input) { SolKeyedAccounts ka[NUM_KA]; uint8_t *data; uint64_t data_len; int err = 0; - if (!sol_deserialize((uint8_t *)input, NUM_KA, ka, &data, &data_len)) { + if (!sol_deserialize(input, NUM_KA, ka, &data, &data_len)) { return false; }