Skip to content

Commit 9f964dc

Browse files
authored
Merge pull request #215 from Zondax/improvements
Improvements
2 parents 9df2d8c + 7255824 commit 9f964dc

File tree

22 files changed

+49
-133
lines changed

22 files changed

+49
-133
lines changed

app/Makefile.version

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,4 @@ APPVERSION_M=2
33
# This is the minor version of this release
44
APPVERSION_N=4
55
# This is the patch version of this release
6-
APPVERSION_P=5
6+
APPVERSION_P=6

app/src/apdu_handler.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@
3232
#include "crypto.h"
3333
#include "coin.h"
3434
#include "zxmacros.h"
35-
#include "secret.h"
3635

3736
static bool tx_initialized = false;
3837

app/src/base32.c

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -31,22 +31,22 @@ uint32_t base32_encode(const uint8_t *data,
3131
uint32_t count = 0;
3232
if (length > 0) {
3333
uint32_t buffer = data[0];
34-
uint32_t next = 1;
35-
uint32_t bitsLeft = 8;
36-
while (count < resultLen && (bitsLeft > 0 || next < length)) {
37-
if (bitsLeft < 5) {
34+
uint32_t next = 1u;
35+
uint32_t bitsLeft = 8u;
36+
while ((count < resultLen) && ((bitsLeft > 0) || (next < length))) {
37+
if (bitsLeft < 5u) {
3838
if (next < length) {
39-
buffer <<= 8;
40-
buffer |= data[next++] & 0xFF;
41-
bitsLeft += 8;
39+
buffer <<= 8u;
40+
buffer |= data[next++] & 0xFFu;
41+
bitsLeft += 8u;
4242
} else {
4343
uint32_t pad = 5u - bitsLeft;
4444
buffer <<= pad;
4545
bitsLeft += pad;
4646
}
4747
}
4848
uint32_t index = 0x1Fu & (buffer >> (bitsLeft - 5u));
49-
bitsLeft -= 5;
49+
bitsLeft -= 5u;
5050
result[count++] = "abcdefghijklmnopqrstuvwxyz234567"[index];
5151
}
5252
}

app/src/base32.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,8 @@
4949
extern "C" {
5050
#endif
5151

52-
uint32_t base32_encode(const uint8_t *data, unsigned int length,
53-
char *result, uint32_t bufSize) __attribute__((visibility("hidden")));
52+
uint32_t base32_encode(const uint8_t *data, uint32_t length,
53+
char *result, uint32_t resultLen) __attribute__((visibility("hidden")));
5454

5555
#ifdef __cplusplus
5656
}

app/src/candid/candid_parser.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -371,7 +371,7 @@ parser_error_t readCandidICRCTransfer(parser_tx_t *tx, const uint8_t *input, uin
371371
CHECK_PARSER_ERR(readCandidNat(&ctx, &icrc->memo.len))
372372

373373
icrc->memo.p = ctx.buffer + ctx.offset;
374-
for (uint8_t i = 0; i < icrc->memo.len; i++) {
374+
for (uint64_t i = 0; i < icrc->memo.len; i++) {
375375
CHECK_PARSER_ERR(readCandidByte(&ctx, &tmp))
376376
}
377377
}
@@ -401,7 +401,10 @@ parser_error_t readCandidICRCTransfer(parser_tx_t *tx, const uint8_t *input, uin
401401
const size_t canisterIdSize = ctx.tx_obj->tx_fields.call.canister_id.len;
402402
char canister_textual[50] = {0};
403403
uint16_t outLen = sizeof(canister_textual);
404-
if (canisterIdSize > 255) return parser_unexpected_value;
404+
if (canisterIdSize > 255) {
405+
return parser_unexpected_value;
406+
}
407+
405408
crypto_principalToTextual(canisterId,
406409
(uint8_t) canisterIdSize,
407410
canister_textual,

app/src/coin.h

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -15,18 +15,18 @@
1515
********************************************************************************/
1616
#pragma once
1717

18+
#include <stdint.h>
19+
#include <stddef.h>
20+
1821
#ifdef __cplusplus
1922
extern "C" {
2023
#endif
2124

22-
#define CLA 0x11
23-
24-
#include <stdint.h>
25-
#include <stddef.h>
25+
#define CLA 0x11u
2626

27-
#define INS_SIGN_COMBINED 0x03
27+
#define INS_SIGN_COMBINED 0x03u
2828

29-
#define HDPATH_LEN_DEFAULT 5
29+
#define HDPATH_LEN_DEFAULT 5u
3030

3131
#define HDPATH_0_DEFAULT (0x80000000u | 0x2cu)
3232
#define HDPATH_1_DEFAULT (0x80000000u | 0xdfu)
@@ -39,13 +39,13 @@ extern "C" {
3939

4040
#define HDPATH_RESTRICTED_MASK 0xFFFFFF00u
4141

42-
#define SECP256K1_PK_LEN 65
43-
#define DFINITY_ADDR_LEN 32
44-
#define DFINITY_SUBACCOUNT_LEN 32
45-
#define DFINITY_PRINCIPAL_LEN 29
46-
#define DFINITY_TEXTUAL_SIZE 100
42+
#define SECP256K1_PK_LEN 65u
43+
#define DFINITY_ADDR_LEN 32u
44+
#define DFINITY_SUBACCOUNT_LEN 32u
45+
#define DFINITY_PRINCIPAL_LEN 29u
46+
#define DFINITY_TEXTUAL_SIZE 100u
4747

48-
#define MAX_CHARS_PER_VALUE_LINE (18)
48+
#define MAX_CHARS_PER_VALUE_LINE 18u
4949

5050
typedef enum {
5151
addr_secp256k1 = 0,

app/src/common/tx.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ uint8_t *tx_get_buffer() {
7070
}
7171

7272
const char *tx_parse() {
73-
uint8_t err = parser_parse(
73+
parser_error_t err = parser_parse(
7474
&ctx_parsed_tx,
7575
tx_get_buffer(),
7676
tx_get_buffer_length());

app/src/crypto.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ zxerr_t crypto_getDigest(uint8_t *digest, txtype_e txtype){
181181
cx_hash_no_throw(&ctx.header, 0, tmpdigest, CX_SHA256_SIZE, NULL, 0);
182182

183183
uint8_t arrayBuffer[PATH_MAX_ARRAY * CX_SHA256_SIZE];
184-
for (uint8_t index = 0; index < fields->paths.arrayLen ; index++){
184+
for (size_t index = 0; index < fields->paths.arrayLen ; index++){
185185
cx_hash_sha256((uint8_t *)fields->paths.paths[index].data, fields->paths.paths[index].len, arrayBuffer + index * CX_SHA256_SIZE, CX_SHA256_SIZE);
186186
}
187187
cx_hash_sha256(arrayBuffer, fields->paths.arrayLen*CX_SHA256_SIZE, tmpdigest, CX_SHA256_SIZE);

app/src/formatting.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,8 @@ zxerr_t inplace_insert_char(char *s, uint16_t sMaxLen, uint16_t pos, char separa
3434

3535
zxerr_t number_inplace_thousands(char *s, uint16_t sMaxLen, char separator) {
3636
const size_t len = strlen(s);
37-
if (len > sMaxLen) {
38-
return zxerr_encoding_failed;
37+
if (len >= sMaxLen) {
38+
return zxerr_buffer_too_small;
3939
}
4040

4141
// find decimal point

app/src/parser.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ static parser_error_t parser_getItemTransactionStateRead(const parser_context_t
160160
CHECK_PARSER_ERR(parser_getNumItems(ctx, &numItems))
161161
CHECK_APP_CANARY()
162162

163-
if (displayIdx < 0 || displayIdx >= numItems) {
163+
if (displayIdx >= numItems) {
164164
return parser_no_data;
165165
}
166166

@@ -180,7 +180,7 @@ static parser_error_t parser_getItemTransactionStateRead(const parser_context_t
180180

181181
displayIdx -= 2;
182182

183-
if (displayIdx < 0 || displayIdx >= fields->paths.arrayLen) {
183+
if (displayIdx >= fields->paths.arrayLen) {
184184
return parser_no_data;
185185
}
186186

0 commit comments

Comments
 (0)