1
0
mirror of https://github.com/trezor/trezor-firmware.git synced 2025-02-09 22:22:38 +00:00

style(legacy): Remove nested conditional operators.

This commit is contained in:
Andrew Kozlik 2021-04-22 16:32:53 +02:00 committed by Andrew Kozlik
parent 334103b089
commit c1843f9f9f
3 changed files with 26 additions and 10 deletions

View File

@ -55,9 +55,17 @@ START_TEST(test_cashaddr) {
rawdata_len = base58_decode_check(valid_cashaddr[i].legacy, HASHER_SHA2D, rawdata_len = base58_decode_check(valid_cashaddr[i].legacy, HASHER_SHA2D,
rawdata, sizeof(rawdata)); rawdata, sizeof(rawdata));
ck_assert_uint_eq(rawdata_len, 21); ck_assert_uint_eq(rawdata_len, 21);
ck_assert_uint_eq(prog[0], rawdata[0] == 0 ? 0x00
: rawdata[0] == 5 ? 0x08 int addr_type = -1;
: -1); if (rawdata[0] == 0) {
addr_type = 0x00; // P2PKH
} else if (rawdata[0] == 5) {
addr_type = 0x08; // P2SH
} else {
ck_abort();
}
ck_assert_uint_eq(prog[0], addr_type);
ck_assert_int_eq(memcmp(rawdata + 1, prog + 1, 20), 0); ck_assert_int_eq(memcmp(rawdata + 1, prog + 1, 20), 0);
ret = cash_addr_encode(rebuild, hrp, prog, 21); ret = cash_addr_encode(rebuild, hrp, prog, 21);
ck_assert_int_eq(ret, 1); ck_assert_int_eq(ret, 1);

View File

@ -779,10 +779,14 @@ void layoutAddress(const char *address, const char *desc, bool qrcode,
oledDrawString(0, 0 * 9, desc, FONT_STANDARD); oledDrawString(0, 0 * 9, desc, FONT_STANDARD);
} }
if (addrlen > 10) { // don't split short addresses if (addrlen > 10) { // don't split short addresses
uint32_t rowlen = (addrlen - 1) / (addrlen <= 42 ? 2 uint32_t rowcount = 4;
: addrlen <= 63 ? 3 if (addrlen <= 42) {
: 4) + rowcount = 2;
1; } else if (addrlen <= 63) {
rowcount = 3;
}
uint32_t rowlen = (addrlen - 1) / rowcount + 1;
const char **str = const char **str =
split_message((const uint8_t *)address, addrlen, rowlen); split_message((const uint8_t *)address, addrlen, rowlen);
for (int i = 0; i < 4; i++) { for (int i = 0; i < 4; i++) {

View File

@ -146,9 +146,13 @@ static void recovery_request(void) {
WordRequest resp = {0}; WordRequest resp = {0};
memzero(&resp, sizeof(WordRequest)); memzero(&resp, sizeof(WordRequest));
resp.has_type = true; resp.has_type = true;
resp.type = awaiting_word == 1 ? WordRequestType_WordRequestType_Plain if (awaiting_word == 1) {
: (word_index % 4 == 3) ? WordRequestType_WordRequestType_Matrix6 resp.type = WordRequestType_WordRequestType_Plain;
: WordRequestType_WordRequestType_Matrix9; } else if (word_index % 4 == 3) {
resp.type = WordRequestType_WordRequestType_Matrix6;
} else {
resp.type = WordRequestType_WordRequestType_Matrix9;
}
msg_write(MessageType_MessageType_WordRequest, &resp); msg_write(MessageType_MessageType_WordRequest, &resp);
} }