Code improvements / Fix warnings
- Fix CodeQL warnings - Port lots of improvements/fixes from PR #225 - replace 'array_hexstr' and '%*H' format by sdk function 'format_hex' - Add 'noreturn' attribute in 'main.c'
This commit is contained in:
@@ -102,11 +102,11 @@ static void eth_plugin_perform_init_default(uint8_t *contractAddress,
|
||||
static bool eth_plugin_perform_init_old_internal(uint8_t *contractAddress,
|
||||
ethPluginInitContract_t *init) {
|
||||
uint8_t i, j;
|
||||
const uint8_t **selectors;
|
||||
const uint8_t *const *selectors;
|
||||
|
||||
// Search internal plugin list
|
||||
for (i = 0;; i++) {
|
||||
selectors = (const uint8_t **) PIC(INTERNAL_ETH_PLUGINS[i].selectors);
|
||||
selectors = (const uint8_t *const *) PIC(INTERNAL_ETH_PLUGINS[i].selectors);
|
||||
if (selectors == NULL) {
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -25,11 +25,11 @@ const uint8_t* const ETH2_SELECTORS[NUM_ETH2_SELECTORS] = {ETH2_DEPOSIT_SELECTOR
|
||||
// All internal alias names start with 'minus'
|
||||
|
||||
const internalEthPlugin_t INTERNAL_ETH_PLUGINS[] = {
|
||||
{NULL, (const uint8_t**) ERC20_SELECTORS, NUM_ERC20_SELECTORS, "-erc20", erc20_plugin_call},
|
||||
{NULL, ERC20_SELECTORS, NUM_ERC20_SELECTORS, "-erc20", erc20_plugin_call},
|
||||
|
||||
#ifdef HAVE_ETH2
|
||||
|
||||
{NULL, (const uint8_t**) ETH2_SELECTORS, NUM_ETH2_SELECTORS, "-eth2", eth2_plugin_call},
|
||||
{NULL, ETH2_SELECTORS, NUM_ETH2_SELECTORS, "-eth2", eth2_plugin_call},
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
@@ -8,12 +8,12 @@
|
||||
void erc721_plugin_call(int message, void* parameters);
|
||||
void erc1155_plugin_call(int message, void* parameters);
|
||||
|
||||
typedef bool (*PluginAvailableCheck)(void);
|
||||
typedef bool (*const PluginAvailableCheck)(void);
|
||||
typedef void (*PluginCall)(int, void*);
|
||||
|
||||
typedef struct internalEthPlugin_t {
|
||||
PluginAvailableCheck availableCheck;
|
||||
const uint8_t** selectors;
|
||||
const uint8_t* const* selectors;
|
||||
uint8_t num_selectors;
|
||||
char alias[10];
|
||||
PluginCall impl;
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
|
||||
#define ZERO(x) explicit_bzero(&x, sizeof(x))
|
||||
|
||||
void handle_check_address(check_address_parameters_t* params, chain_config_t* chain_config) {
|
||||
void handle_check_address(check_address_parameters_t* params, const chain_config_t* chain_config) {
|
||||
params->result = 0;
|
||||
PRINTF("Params on the address %d\n", (unsigned int) params);
|
||||
PRINTF("Address to check %s\n", params->address_to_check);
|
||||
|
||||
@@ -5,6 +5,6 @@
|
||||
#include "chainConfig.h"
|
||||
|
||||
void handle_check_address(check_address_parameters_t* check_address_params,
|
||||
chain_config_t* chain_config);
|
||||
const chain_config_t* chain_config);
|
||||
|
||||
#endif // _HANDLE_CHECK_ADDRESS_H_
|
||||
|
||||
@@ -14,7 +14,7 @@
|
||||
static uint8_t* G_swap_sign_return_value_address;
|
||||
|
||||
bool copy_transaction_parameters(create_transaction_parameters_t* sign_transaction_params,
|
||||
chain_config_t* config) {
|
||||
const chain_config_t* config) {
|
||||
// first copy parameters to stack, and then to global data.
|
||||
// We need this "trick" as the input data position can overlap with app-ethereum globals
|
||||
txStringProperties_t stack_data;
|
||||
@@ -80,7 +80,7 @@ void __attribute__((noreturn)) finalize_exchange_sign_transaction(bool is_succes
|
||||
os_lib_end();
|
||||
}
|
||||
|
||||
void __attribute__((noreturn)) handle_swap_sign_transaction(chain_config_t* config) {
|
||||
void __attribute__((noreturn)) handle_swap_sign_transaction(const chain_config_t* config) {
|
||||
#ifdef HAVE_NBGL
|
||||
// On Stax, display a spinner at startup
|
||||
UX_INIT();
|
||||
|
||||
@@ -4,8 +4,8 @@
|
||||
#include "chainConfig.h"
|
||||
|
||||
bool copy_transaction_parameters(create_transaction_parameters_t* sign_transaction_params,
|
||||
chain_config_t* config);
|
||||
const chain_config_t* config);
|
||||
|
||||
void __attribute__((noreturn)) handle_swap_sign_transaction(chain_config_t* config);
|
||||
void __attribute__((noreturn)) handle_swap_sign_transaction(const chain_config_t* config);
|
||||
|
||||
void __attribute__((noreturn)) finalize_exchange_sign_transaction(bool is_success);
|
||||
|
||||
12
src/main.c
12
src/main.c
@@ -67,7 +67,7 @@ const internalStorage_t N_storage_real;
|
||||
#ifdef HAVE_NBGL
|
||||
caller_app_t *caller_app = NULL;
|
||||
#endif
|
||||
chain_config_t *chainConfig = NULL;
|
||||
const chain_config_t *chainConfig;
|
||||
|
||||
void reset_app_context() {
|
||||
// PRINTF("!!RESET_APP_CONTEXT\n");
|
||||
@@ -114,7 +114,7 @@ unsigned short io_exchange_al(unsigned char channel, unsigned short tx_len) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
extraInfo_t *getKnownToken(uint8_t *contractAddress) {
|
||||
extraInfo_t *getKnownToken(const uint8_t *contractAddress) {
|
||||
union extraInfo_t *currentItem = NULL;
|
||||
// Works for ERC-20 & NFT tokens since both structs in the union have the
|
||||
// contract address aligned
|
||||
@@ -456,7 +456,7 @@ void app_main(void) {
|
||||
// override point, but nothing more to do
|
||||
#ifdef HAVE_BAGL
|
||||
void io_seproxyhal_display(const bagl_element_t *element) {
|
||||
io_seproxyhal_display_default((bagl_element_t *) element);
|
||||
io_seproxyhal_display_default(element);
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -526,7 +526,7 @@ void init_coin_config(chain_config_t *coin_config) {
|
||||
coin_config->chainId = CHAIN_ID;
|
||||
}
|
||||
|
||||
void coin_main(libargs_t *args) {
|
||||
__attribute__((noreturn)) void coin_main(libargs_t *args) {
|
||||
chain_config_t config;
|
||||
if (args) {
|
||||
if (args->chain_config != NULL) {
|
||||
@@ -612,10 +612,10 @@ void coin_main(libargs_t *args) {
|
||||
}
|
||||
END_TRY;
|
||||
}
|
||||
app_exit();
|
||||
os_sched_exit(-1);
|
||||
}
|
||||
|
||||
void library_main(libargs_t *args) {
|
||||
__attribute__((noreturn)) void library_main(libargs_t *args) {
|
||||
chain_config_t coin_config;
|
||||
if (args->chain_config == NULL) {
|
||||
// We have been started directly by Exchange, not by a Clone. Init default chain
|
||||
|
||||
@@ -147,7 +147,7 @@ typedef union {
|
||||
strDataTmp_t tmp;
|
||||
} strings_t;
|
||||
|
||||
extern chain_config_t *chainConfig;
|
||||
extern const chain_config_t *chainConfig;
|
||||
|
||||
extern tmpCtx_t tmpCtx;
|
||||
extern txContext_t txContext;
|
||||
|
||||
@@ -26,6 +26,6 @@ void ui_warning_contract_data(void);
|
||||
|
||||
void io_seproxyhal_send_status(uint32_t sw);
|
||||
void finalizeParsing(bool direct);
|
||||
extraInfo_t *getKnownToken(uint8_t *contractAddress);
|
||||
extraInfo_t *getKnownToken(const uint8_t *contractAddress);
|
||||
|
||||
#endif // _UI_CALLBACKS_H_
|
||||
|
||||
@@ -53,11 +53,9 @@ void shiftl128(const uint128_t *const number, uint32_t value, uint128_t *const t
|
||||
} else if (value < 64) {
|
||||
UPPER_P(target) = (UPPER_P(number) << value) + (LOWER_P(number) >> (64 - value));
|
||||
LOWER_P(target) = (LOWER_P(number) << value);
|
||||
} else if ((128 > value) && (value > 64)) {
|
||||
} else {
|
||||
UPPER_P(target) = LOWER_P(number) << (value - 64);
|
||||
LOWER_P(target) = 0;
|
||||
} else {
|
||||
clear128(target);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -74,11 +72,9 @@ void shiftr128(const uint128_t *const number, uint32_t value, uint128_t *const t
|
||||
UPPER(result) = UPPER_P(number) >> value;
|
||||
LOWER(result) = (UPPER_P(number) << (64 - value)) + (LOWER_P(number) >> value);
|
||||
copy128(target, &result);
|
||||
} else if ((128 > value) && (value > 64)) {
|
||||
} else {
|
||||
LOWER_P(target) = UPPER_P(number) >> (value - 64);
|
||||
UPPER_P(target) = 0;
|
||||
} else {
|
||||
clear128(target);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -59,11 +59,9 @@ void shiftl256(const uint256_t *const number, uint32_t value, uint256_t *const t
|
||||
add128(&tmp1, &tmp2, &UPPER(result));
|
||||
shiftl128(&LOWER_P(number), value, &LOWER(result));
|
||||
copy256(target, &result);
|
||||
} else if ((256 > value) && (value > 128)) {
|
||||
} else {
|
||||
shiftl128(&LOWER_P(number), (value - 128), &UPPER_P(target));
|
||||
clear128(&LOWER_P(target));
|
||||
} else {
|
||||
clear256(target);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -84,11 +82,9 @@ void shiftr256(const uint256_t *const number, uint32_t value, uint256_t *const t
|
||||
shiftl128(&UPPER_P(number), (128 - value), &tmp2);
|
||||
add128(&tmp1, &tmp2, &LOWER(result));
|
||||
copy256(target, &result);
|
||||
} else if ((256 > value) && (value > 128)) {
|
||||
} else {
|
||||
shiftr128(&UPPER_P(number), (value - 128), &LOWER_P(target));
|
||||
clear128(&UPPER_P(target));
|
||||
} else {
|
||||
clear256(target);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -58,3 +58,20 @@ void reverseString(char *const str, uint32_t length) {
|
||||
str[j] = c;
|
||||
}
|
||||
}
|
||||
|
||||
int bytes_to_string(char *out, size_t outl, const void *value, size_t len) {
|
||||
if (outl <= 2) {
|
||||
// Need at least '0x' and 1 digit
|
||||
return -1;
|
||||
}
|
||||
if (strlcpy(out, "0x", outl) != 2) {
|
||||
goto err;
|
||||
}
|
||||
if (format_hex(value, len, out + 2, outl - 2) < 0) {
|
||||
goto err;
|
||||
}
|
||||
return 0;
|
||||
err:
|
||||
*out = '\0';
|
||||
return -1;
|
||||
}
|
||||
|
||||
@@ -21,6 +21,9 @@
|
||||
#define _UINT_COMMON_H_
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include "format.h"
|
||||
|
||||
#define UPPER_P(x) x->elements[0]
|
||||
#define LOWER_P(x) x->elements[1]
|
||||
@@ -32,4 +35,6 @@ void read_u64_be(const uint8_t *const in, uint64_t *const out);
|
||||
uint64_t readUint64BE(const uint8_t *const buffer);
|
||||
void reverseString(char *const str, uint32_t length);
|
||||
|
||||
int bytes_to_string(char *out, size_t outl, const void *value, size_t len);
|
||||
|
||||
#endif //_UINT_COMMON_H_
|
||||
|
||||
Reference in New Issue
Block a user