From b35fc03a649a7f4286a2d139772a6e39122d33aa Mon Sep 17 00:00:00 2001 From: Alexandre Paillier Date: Wed, 6 Jul 2022 18:04:29 +0200 Subject: [PATCH] Small simplification/refactoring of EIP712 solidity typenames matching --- src_features/signMessageEIP712/sol_typenames.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src_features/signMessageEIP712/sol_typenames.c b/src_features/signMessageEIP712/sol_typenames.c index 79b9ee7..ec9fa53 100644 --- a/src_features/signMessageEIP712/sol_typenames.c +++ b/src_features/signMessageEIP712/sol_typenames.c @@ -21,14 +21,14 @@ enum IDX_COUNT }; -static bool find_enum_matches(const uint8_t (*enum_to_idx)[TYPES_COUNT - 1][IDX_COUNT], uint8_t s_idx) +static bool find_enum_matches(const uint8_t enum_to_idx[TYPES_COUNT - 1][IDX_COUNT], uint8_t s_idx) { uint8_t *enum_match = NULL; // loop over enum/typename pairs - for (uint8_t e_idx = 0; e_idx < ARRAY_SIZE(*enum_to_idx); ++e_idx) + for (uint8_t e_idx = 0; e_idx < (TYPES_COUNT - 1); ++e_idx) { - if (s_idx == (*enum_to_idx)[e_idx][IDX_STR_IDX]) // match + if (s_idx == enum_to_idx[e_idx][IDX_STR_IDX]) // match { if (enum_match != NULL) // in case of a previous match, mark it { @@ -39,7 +39,7 @@ static bool find_enum_matches(const uint8_t (*enum_to_idx)[TYPES_COUNT - 1][IDX_ apdu_response_code = APDU_RESPONSE_INSUFFICIENT_MEMORY; return false; } - *enum_match = (*enum_to_idx)[e_idx][IDX_ENUM]; + *enum_match = enum_to_idx[e_idx][IDX_ENUM]; } } return (enum_match != NULL); @@ -77,7 +77,7 @@ bool sol_typenames_init(void) for (uint8_t s_idx = 0; s_idx < ARRAY_SIZE(typenames); ++s_idx) { // if at least one match was found - if (find_enum_matches(&enum_to_idx, s_idx)) + if (find_enum_matches(enum_to_idx, s_idx)) { if ((typename_len_ptr = mem_alloc(sizeof(uint8_t))) == NULL) {