From a231c8972dcc8e41d18f04df415ea85a2b7f9631 Mon Sep 17 00:00:00 2001 From: OleksiiM Date: Wed, 29 Jan 2025 15:17:19 +0000 Subject: [PATCH] update clang-format --- src/common/parse.c | 25 ++++++++++++------------- src/common/parse.h | 1 - src/handler/get_public_key.c | 16 ++++++---------- src/handler/get_public_key.h | 10 +++++----- src/swap/handle_check_address.c | 10 +++++++--- src/swap/handle_get_printable_amount.c | 7 +++---- 6 files changed, 33 insertions(+), 36 deletions(-) diff --git a/src/common/parse.c b/src/common/parse.c index 144b8a7..25c36b5 100644 --- a/src/common/parse.c +++ b/src/common/parse.c @@ -18,7 +18,7 @@ #include #include "parse.h" -#define MAX_AMOUNT_STR_LEN 21 // 19 for u64 + 1 for '\0' +1 for '.' +#define MAX_AMOUNT_STR_LEN 21 // 19 for u64 + 1 for '\0' +1 for '.' bool adjustDecimals(const char *src, uint32_t srcLength, @@ -36,11 +36,11 @@ bool adjustDecimals(const char *src, } target[offset++] = '0'; target[offset++] = '.'; - for (uint32_t i = 0; i < delta; i++) { + for (uint32_t i = 0; i < delta; i++) { target[offset++] = '0'; } startOffset = offset; - for (uint32_t i = 0; i < srcLength; i++) { + for (uint32_t i = 0; i < srcLength; i++) { target[offset++] = src[i]; } target[offset] = '\0'; @@ -50,14 +50,14 @@ bool adjustDecimals(const char *src, if (targetLength < srcLength + 1 + 1) { return false; } - while (offset < delta) { + while (offset < delta) { target[offset++] = src[sourceOffset++]; } if (decimals != 0) { target[offset++] = '.'; } startOffset = offset; - while (sourceOffset < srcLength) { + while (sourceOffset < srcLength) { target[offset++] = src[sourceOffset++]; } target[offset] = '\0'; @@ -71,7 +71,7 @@ bool adjustDecimals(const char *src, lastZeroOffset = 0; } } - if (lastZeroOffset != 0) { + if (lastZeroOffset != 0) { target[lastZeroOffset] = '\0'; if (target[lastZeroOffset - 1] == '.') { target[lastZeroOffset - 1] = '\0'; @@ -80,24 +80,23 @@ bool adjustDecimals(const char *src, return true; } unsigned short print_amount(uint64_t amount, char *out, uint32_t outlen, uint8_t decimals) { - if (amount == 0) { if (outlen < 2) { return 0; } out[0] = '0'; - out[1] = '\0'; + out[1] = '\0'; return strlen(out); } - char tmp[MAX_AMOUNT_STR_LEN]; + char tmp[MAX_AMOUNT_STR_LEN]; char tmp2[MAX_AMOUNT_STR_LEN]; uint32_t numDigits = 0, i; uint64_t base = 1; - while (base <= amount) { - base *= 10; + while (base <= amount) { + base *= 10; numDigits++; } if (numDigits > sizeof(tmp) - 2) { @@ -110,10 +109,10 @@ unsigned short print_amount(uint64_t amount, char *out, uint32_t outlen, uint8_t } tmp[i] = '\0'; out[0] = '\0'; - if ( adjustDecimals(tmp, i, tmp2, MAX_AMOUNT_STR_LEN, decimals) ) { + if (adjustDecimals(tmp, i, tmp2, MAX_AMOUNT_STR_LEN, decimals)) { if (strlen(tmp2) < outlen - 1) { strlcpy(out, tmp2, outlen); } - } + } return strlen(out); } diff --git a/src/common/parse.h b/src/common/parse.h index 87cd77e..d733976 100644 --- a/src/common/parse.h +++ b/src/common/parse.h @@ -1,6 +1,5 @@ #include "os.h" - #ifndef PARSE_H #define PARSE_H diff --git a/src/handler/get_public_key.c b/src/handler/get_public_key.c index b3fdc8f..7652178 100644 --- a/src/handler/get_public_key.c +++ b/src/handler/get_public_key.c @@ -71,9 +71,9 @@ #include "../helper/send_response.h" int get_public_key(buffer_t *cdata, - uint8_t *output_bip32_path_len, - uint32_t *output_bip32_path, - pubkey_ctx_t *output_pubkey_ctx) { + uint8_t *output_bip32_path_len, + uint32_t *output_bip32_path, + pubkey_ctx_t *output_pubkey_ctx) { if (!buffer_read_u8(cdata, output_bip32_path_len)) { return io_send_sw(SW_WRONG_DATA_LENGTH); } @@ -101,7 +101,7 @@ int get_public_key(buffer_t *cdata, // Generate corresponding public key cx_ecfp_public_key_t public_key = {0}; error = crypto_init_public_key(&private_key, &public_key, output_pubkey_ctx->raw_public_key); - // Wipe the private key from memory to protect against memory attacks + // Wipe the private key from memory to protect against memory attacks explicit_bzero(&private_key, sizeof(private_key)); if (error != CX_OK) { @@ -116,10 +116,8 @@ int handler_get_public_key(buffer_t *cdata, bool display) { explicit_bzero(&G_context, sizeof(G_context)); G_context.req_type = CONFIRM_ADDRESS; - int err = get_public_key(cdata, - &G_context.bip32_path_len, - G_context.bip32_path, - &G_context.pk_info); + int err = + get_public_key(cdata, &G_context.bip32_path_len, G_context.bip32_path, &G_context.pk_info); if (err) { G_context.req_type = REQUEST_UNDEFINED; @@ -135,5 +133,3 @@ int handler_get_public_key(buffer_t *cdata, bool display) { G_context.req_type = REQUEST_UNDEFINED; // all the work is done, reset the context return helper_send_response_pubkey(); } - - diff --git a/src/handler/get_public_key.h b/src/handler/get_public_key.h index 59eb6f7..8bcb70f 100644 --- a/src/handler/get_public_key.h +++ b/src/handler/get_public_key.h @@ -28,7 +28,7 @@ int handler_get_public_key(buffer_t *cdata, bool display); /** * Helper function for GET_PUBLIC_KEY and CHECK_ADDRESS command. If successfully parse * BIP32 path, derive public key/chain. The public key is stored in output_public_key, - * and the BIP32 path and its length are stored in output_bip32_path and + * and the BIP32 path and its length are stored in output_bip32_path and * output_bip32_path_len respectively. * * @param[in] cdata @@ -39,11 +39,11 @@ int handler_get_public_key(buffer_t *cdata, bool display); * Buffer to store the BIP32 path. * @param[out] output_public_key * Buffer to store the public key. - * + * * @return zero if success, error code otherwise. * */ int get_public_key(buffer_t *cdata, - uint8_t *output_bip32_path_len, - uint32_t output_bip32_path[MAX_BIP32_PATH], - pubkey_ctx_t *output_public_key); + uint8_t *output_bip32_path_len, + uint32_t output_bip32_path[MAX_BIP32_PATH], + pubkey_ctx_t *output_public_key); diff --git a/src/swap/handle_check_address.c b/src/swap/handle_check_address.c index 7d5b5aa..8a3a3eb 100644 --- a/src/swap/handle_check_address.c +++ b/src/swap/handle_check_address.c @@ -45,7 +45,9 @@ void swap_handle_check_address(check_address_parameters_t *params) { return; } PRINTF("address_parameters_length: %d\n", params->address_parameters_length); - PRINTF("address_parameters: %.*H\n", params->address_parameters_length, params->address_parameters); + PRINTF("address_parameters: %.*H\n", + params->address_parameters_length, + params->address_parameters); if (params->address_to_check == NULL) { PRINTF("address_to_check is empty\n"); @@ -54,7 +56,8 @@ void swap_handle_check_address(check_address_parameters_t *params) { if (strlen(params->address_to_check) != ADDRESS_STRING_LENGTH) { PRINTF("address_to_check length should be %d, not %d\n", - ADDRESS_STRING_LENGTH, strlen(params->address_to_check)); + ADDRESS_STRING_LENGTH, + strlen(params->address_to_check)); return; } @@ -77,7 +80,8 @@ void swap_handle_check_address(check_address_parameters_t *params) { return; } char prefixed_address[ADDRESS_STRING_LENGTH + 1]; - if (0 > format_prefixed_hex(address, sizeof(address), prefixed_address, sizeof(prefixed_address))) { + if (0 > + format_prefixed_hex(address, sizeof(address), prefixed_address, sizeof(prefixed_address))) { return; } diff --git a/src/swap/handle_get_printable_amount.c b/src/swap/handle_get_printable_amount.c index 1d033dc..bf9176a 100644 --- a/src/swap/handle_get_printable_amount.c +++ b/src/swap/handle_get_printable_amount.c @@ -8,8 +8,7 @@ /* Set empty printable_amount on error, printable amount otherwise */ void swap_handle_get_printable_amount(get_printable_amount_parameters_t* params) { - - uint64_t amount; + uint64_t amount; uint8_t decimals; char ticker[MAX_TICKER_LEN] = {0}; @@ -18,8 +17,8 @@ void swap_handle_get_printable_amount(get_printable_amount_parameters_t* params) // If the amount is a fee, its value is nominated in APT // If there is no coin_configuration, consider that we are doing a APT swap if (params->is_fee || params->coin_configuration == NULL) { - memcpy(ticker, "APT", sizeof("APT")); - decimals = APT_DECIMAL_PRECISION; + memcpy(ticker, "APT", sizeof("APT")); + decimals = APT_DECIMAL_PRECISION; } else { if (!swap_parse_config(params->coin_configuration, params->coin_configuration_length,