From 10fbb8d5bc59f8aaa86c97307c8c93ba23d4368c Mon Sep 17 00:00:00 2001 From: Alexandre Paillier Date: Tue, 7 Jun 2022 14:44:01 +0200 Subject: [PATCH] Unify all the hex digits used in the app --- src/utils.c | 7 ++----- src_common/ethUtils.c | 2 -- src_common/uint128.c | 1 + src_common/uint256.c | 3 ++- src_common/uint_common.c | 2 -- src_common/uint_common.h | 2 -- 6 files changed, 5 insertions(+), 12 deletions(-) diff --git a/src/utils.c b/src/utils.c index 791b015..f044e98 100644 --- a/src/utils.c +++ b/src/utils.c @@ -24,13 +24,10 @@ #include "tokens.h" #include "utils.h" -static const unsigned char hex_digits[] = - {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F'}; - void array_hexstr(char *strbuf, const void *bin, unsigned int len) { while (len--) { - *strbuf++ = hex_digits[((*((char *) bin)) >> 4) & 0xF]; - *strbuf++ = hex_digits[(*((char *) bin)) & 0xF]; + *strbuf++ = HEXDIGITS[((*((char *) bin)) >> 4) & 0xF]; + *strbuf++ = HEXDIGITS[(*((char *) bin)) & 0xF]; bin = (const void *) ((unsigned int) bin + 1); } *strbuf = 0; // EOS diff --git a/src_common/ethUtils.c b/src_common/ethUtils.c index 804837c..4dd0e6a 100644 --- a/src_common/ethUtils.c +++ b/src_common/ethUtils.c @@ -27,8 +27,6 @@ #include #include -#include "os.h" -#include "cx.h" #include "ethUtils.h" #include "chainConfig.h" #include "ethUstream.h" diff --git a/src_common/uint128.c b/src_common/uint128.c index 1962cc8..79cf2ac 100644 --- a/src_common/uint128.c +++ b/src_common/uint128.c @@ -21,6 +21,7 @@ #include #include "uint128.h" #include "uint_common.h" +#include "ethUtils.h" // HEXDIGITS void readu128BE(const uint8_t *const buffer, uint128_t *const target) { UPPER_P(target) = readUint64BE(buffer); diff --git a/src_common/uint256.c b/src_common/uint256.c index 68ac0a3..54b165b 100644 --- a/src_common/uint256.c +++ b/src_common/uint256.c @@ -19,9 +19,10 @@ #include #include -#include "ethUstream.h" // INT256_LENGTH #include "uint256.h" #include "uint_common.h" +#include "ethUstream.h" // INT256_LENGTH +#include "ethUtils.h" // HEXDIGITS void readu256BE(const uint8_t *const buffer, uint256_t *const target) { readu128BE(buffer, &UPPER_P(target)); diff --git a/src_common/uint_common.c b/src_common/uint_common.c index 237641c..5fe06a7 100644 --- a/src_common/uint_common.c +++ b/src_common/uint_common.c @@ -19,8 +19,6 @@ #include "uint_common.h" -const char HEXDIGITS[] = "0123456789abcdef"; - void write_u64_be(uint8_t *const buffer, uint64_t value) { buffer[0] = ((value >> 56) & 0xff); buffer[1] = ((value >> 48) & 0xff); diff --git a/src_common/uint_common.h b/src_common/uint_common.h index 3f2fec1..4a22171 100644 --- a/src_common/uint_common.h +++ b/src_common/uint_common.h @@ -27,8 +27,6 @@ #define UPPER(x) x.elements[0] #define LOWER(x) x.elements[1] -extern const char HEXDIGITS[]; - void write_u64_be(uint8_t *const buffer, uint64_t value); void read_u64_be(const uint8_t *const in, uint64_t *const out); uint64_t readUint64BE(const uint8_t *const buffer);