Fix all the defects identified by Clang Static Analyzer

Some fixes are dirty, but it is a start to enforce scan-build on
every commit.

Signed-off-by: pscott <scott.piriou@ledger.fr>
This commit is contained in:
Jean-Baptiste Bédrune
2021-07-16 12:04:39 +02:00
committed by pscott
parent c27d59d792
commit cd78581ffd
15 changed files with 158 additions and 144 deletions

View File

@@ -16,10 +16,10 @@ typedef struct erc20_parameters_t {
uint8_t selectorIndex;
uint8_t destinationAddress[21];
uint8_t amount[INT256_LENGTH];
uint8_t ticker[MAX_TICKER_LEN];
char ticker[MAX_TICKER_LEN];
uint8_t decimals;
uint8_t target;
uint8_t contract_name[MAX_CONTRACT_NAME_LEN];
char contract_name[MAX_CONTRACT_NAME_LEN];
} erc20_parameters_t;
typedef struct contract_t {
@@ -58,9 +58,7 @@ bool check_contract(erc20_parameters_t *context) {
for (size_t i = 0; i < NUM_CONTRACTS; i++) {
contract_t *contract = (contract_t *) PIC(&CONTRACTS[i]);
if (memcmp(contract->address, context->destinationAddress, ADDRESS_LENGTH) == 0) {
strncpy((char *) context->contract_name,
contract->name,
sizeof(context->contract_name));
strncpy(context->contract_name, contract->name, sizeof(context->contract_name));
return true;
}
}
@@ -161,7 +159,7 @@ void erc20_plugin_call(int message, void *parameters) {
(msg->token2 != NULL));
if (msg->token1 != NULL) {
context->target = TARGET_ADDRESS;
strcpy((char *) context->ticker, (char *) msg->token1->ticker);
strlcpy(context->ticker, msg->token1->ticker, MAX_TICKER_LEN);
context->decimals = msg->token1->decimals;
if (context->selectorIndex == ERC20_APPROVE) {
if (check_contract(context)) {
@@ -176,8 +174,8 @@ void erc20_plugin_call(int message, void *parameters) {
case ETH_PLUGIN_QUERY_CONTRACT_ID: {
ethQueryContractID_t *msg = (ethQueryContractID_t *) parameters;
strcpy(msg->name, "Type");
strcpy(msg->version, "Approve");
strlcpy(msg->name, "Type", msg->nameLength);
strlcpy(msg->version, "Approve", msg->versionLength);
msg->result = ETH_PLUGIN_RESULT_OK;
} break;
@@ -186,15 +184,15 @@ void erc20_plugin_call(int message, void *parameters) {
erc20_parameters_t *context = (erc20_parameters_t *) msg->pluginContext;
switch (msg->screenIndex) {
case 0:
strcpy(msg->title, "Amount");
strlcpy(msg->title, "Amount", msg->titleLength);
if (ismaxint(context->amount, sizeof(context->amount))) {
strcpy(msg->msg, "Unlimited ");
strcat(msg->msg, (char *) context->ticker);
strlcpy(msg->msg, "Unlimited ", msg->msgLength);
strlcat(msg->msg, context->ticker, msg->msgLength);
} else {
amountToString(context->amount,
sizeof(context->amount),
context->decimals,
(char *) context->ticker,
context->ticker,
msg->msg,
100);
}
@@ -202,10 +200,10 @@ void erc20_plugin_call(int message, void *parameters) {
break;
case 1:
if (context->target >= TARGET_CONTRACT) {
strcpy(msg->title, "Contract");
strcpy(msg->msg, (char *) context->contract_name);
strlcpy(msg->title, "Contract", msg->titleLength);
strlcpy(msg->msg, context->contract_name, msg->msgLength);
} else {
strcpy(msg->title, "Address");
strlcpy(msg->title, "Address", msg->titleLength);
msg->msg[0] = '0';
msg->msg[1] = 'x';
getEthAddressStringFromBinary(context->destinationAddress,