Skip to content

Commit

Permalink
Fix static analysis warnings
Browse files Browse the repository at this point in the history
Static analysis detected some issues in the code. This commit fixes
them to let CI pass.
  • Loading branch information
italo-sampaio committed Dec 14, 2023
1 parent e6f54c9 commit 3701551
Show file tree
Hide file tree
Showing 6 changed files with 10 additions and 9 deletions.
4 changes: 2 additions & 2 deletions ledger/src/signer/src/auth_trie.c
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ static void trie_cb(const trie_cb_event_t event) {
switch (event) {
case TRIE_EV_FLAGS:
if (TRIE_FG_VERSION(auth.trie.ctx.flags) != AUTH_TRIE_NODE_VERSION) {
LOG("[E] Invalid node version: %u\n",
LOG("[E] Invalid node version: %d\n",
TRIE_FG_VERSION(auth.trie.ctx.flags));
THROW(ERR_AUTH_NODE_INVALID_VERSION);
}
Expand Down Expand Up @@ -209,7 +209,7 @@ unsigned int auth_sign_handle_merkleproof(volatile unsigned int rx) {
APDU_DATA_SIZE(rx) - apdu_offset);

if (trie_result() < 0) {
LOG("[E] Error parsing MP node: %u\n", trie_result());
LOG("[E] Error parsing MP node: %d\n", trie_result());
// Reusing an existing error code due to legacy protocol
THROW(ERR_AUTH_RECEIPT_ROOT_MISMATCH);
} else if (trie_result() == TRIE_ST_DONE) {
Expand Down
4 changes: 2 additions & 2 deletions ledger/src/signer/src/auth_tx.c
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ static void btctx_cb(const btctx_cb_event_t event) {
}

if (btcscript_result() < 0) {
LOG("[E] Error %u parsing the scriptSig", btcscript_result());
LOG("[E] Error %d parsing the scriptSig", btcscript_result());
THROW(ERR_AUTH_TX_HASH_MISMATCH);
}

Expand Down Expand Up @@ -184,7 +184,7 @@ unsigned int auth_sign_handle_btctx(volatile unsigned int rx) {
// Add SIGHASH_ALL hash type at the end
sha256_update(&auth.tx.sig_hash_ctx,
(uint8_t[])SIGHASH_ALL_BYTES,
sizeof(SIGHASH_ALL_SIZE));
sizeof((uint8_t[])SIGHASH_ALL_BYTES));
sha256_final(&auth.tx.sig_hash_ctx, auth.sig_hash);

sha256_init(&auth.tx.sig_hash_ctx);
Expand Down
1 change: 0 additions & 1 deletion ledger/src/signer/src/auth_tx.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@
#include "btcscript.h"

#define BTCTX_LENGTH_SIZE 4
#define SIGHASH_ALL_SIZE 4
#define SIGHASH_ALL_BYTES \
{ 0x01, 0x00, 0x00, 0x00 }

Expand Down
2 changes: 1 addition & 1 deletion ledger/src/signer/src/bc_ancestor.c
Original file line number Diff line number Diff line change
Expand Up @@ -341,7 +341,7 @@ unsigned int bc_upd_ancestor(volatile unsigned int rx) {
// OP_HEADER_META
// -------------------------------------------------------------------
if (op == OP_UPD_ANCESTOR_HEADER_META) {
LOG("---- Block %u of %u\n", curr_block + 1, expected_blocks);
LOG("---- Block %lu of %lu\n", curr_block + 1, expected_blocks);

// Clear block data
memset(&block, 0, sizeof(block));
Expand Down
4 changes: 3 additions & 1 deletion ledger/src/tcpsigner/json.c
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,10 @@ cJSON* read_json_file(char* file_path) {

// Allocate buffer
buffer = (char*)malloc(file_size * sizeof(char));
if (buffer == NULL)
if (buffer == NULL) {
fclose(key_file);
return NULL;
}

// Read into buffer and close the file
fread(buffer, sizeof(char), file_size, key_file);
Expand Down
4 changes: 2 additions & 2 deletions ledger/src/tcpsigner/tcpsigner.c
Original file line number Diff line number Diff line change
Expand Up @@ -382,7 +382,7 @@ void main(int argc, char **argv) {
#ifdef __AFL_HAVE_MANUAL_CONTROL
while (__AFL_LOOP(10000)) {
#endif
FILE *inputfd;
FILE *inputfd = NULL;
if (arguments.filemode) {
info("Using file %s as input\n", arguments.inputfile);
if ((inputfd = fopen(arguments.inputfile, "rb")) == NULL) {
Expand All @@ -399,7 +399,7 @@ void main(int argc, char **argv) {
os_io_set_server(server);
}

FILE *replicafd;
FILE *replicafd = NULL;
if (strlen(arguments.replicafile) > 0) {
info("Using file %s as replica\n", arguments.replicafile);
if ((replicafd = fopen(arguments.replicafile, "ab")) == NULL) {
Expand Down

0 comments on commit 3701551

Please sign in to comment.