Skip to content

Commit 58cd6a9

Browse files
committed
fix warnings
1 parent e5141b6 commit 58cd6a9

2 files changed

Lines changed: 52 additions & 21 deletions

File tree

app/src/borsh.c

Lines changed: 41 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,10 @@
2020

2121
void print_buffer(bytes_t *buffer, const char *title) {
2222
#if defined(LEDGER_SPECIFIC)
23-
ZEMU_LOGF(50, "%s\n", title);
2423
char print[1000] = {0};
24+
MEMCPY(print, title, strlen(title));
25+
ZEMU_LOGF(50, "%s\n", print);
26+
MEMZERO(print, sizeof(print));
2527
array_to_hexstr(print, sizeof(print), buffer->ptr, buffer->len);
2628
ZEMU_LOGF(1000, "%s\n", print);
2729
#else
@@ -35,8 +37,10 @@ void print_buffer(bytes_t *buffer, const char *title) {
3537

3638
void print_buffer_u8(bytes_t *buffer, const char *title) {
3739
#if defined(LEDGER_SPECIFIC)
38-
ZEMU_LOGF(50, "%s\n", title);
3940
char print[1000] = {0};
41+
MEMCPY(print, title, strlen(title));
42+
ZEMU_LOGF(50, "%s\n", print);
43+
MEMZERO(print, sizeof(print));
4044
array_to_hexstr(print, sizeof(print), buffer->ptr, buffer->len);
4145
ZEMU_LOGF(1000, "%s\n", print);
4246
#else
@@ -50,8 +54,10 @@ void print_buffer_u8(bytes_t *buffer, const char *title) {
5054

5155
void print_buffer_str(bytes_t *buffer, const char *title) {
5256
#if defined(LEDGER_SPECIFIC)
53-
ZEMU_LOGF(50, "%s\n", title);
5457
char print[1000] = {0};
58+
MEMCPY(print, title, strlen(title));
59+
ZEMU_LOGF(50, "%s\n", print);
60+
MEMZERO(print, sizeof(print));
5561
array_to_hexstr(print, sizeof(print), buffer->ptr, buffer->len);
5662
ZEMU_LOGF(1000, "%s\n", print);
5763
#else
@@ -63,55 +69,80 @@ void print_buffer_str(bytes_t *buffer, const char *title) {
6369

6470
void print_string(const char *str) {
6571
#if defined(LEDGER_SPECIFIC)
66-
ZEMU_LOGF(100, "%s\n", str);
72+
char print[1000] = {0};
73+
MEMCPY(print, str, strlen(str));
74+
ZEMU_LOGF(100, "%s\n", print);
6775
#else
6876
printf("%s\n", str);
6977
#endif
7078
}
7179

7280
void print_string_title(const char *str, const char *title) {
7381
#if defined(LEDGER_SPECIFIC)
74-
ZEMU_LOGF(100, "%s: %s\n", title, str);
82+
char print[1000] = {0};
83+
MEMCPY(print, title, strlen(title));
84+
MEMCPY(print + strlen(title), str, strlen(str));
85+
ZEMU_LOGF(100, "%s\n", print);
7586
#else
7687
printf("%s: %s\n", title, str);
7788
#endif
7889
}
7990

8091
void print_u8(const char *str, uint8_t val) {
8192
#if defined(LEDGER_SPECIFIC)
82-
ZEMU_LOGF(100, "%s: %d\n", str, val);
93+
char print[1000] = {0};
94+
MEMCPY(print, str, strlen(str));
95+
MEMCPY(print + strlen(str), ": ", 2);
96+
MEMCPY(print + strlen(str) + 2, &val, sizeof(val));
97+
ZEMU_LOGF(100, "%s\n", print);
8398
#else
8499
printf("%s: %d\n", str, val);
85100
#endif
86101
}
87102

88103
void print_u16(const char *str, uint16_t val) {
89104
#if defined(LEDGER_SPECIFIC)
90-
ZEMU_LOGF(100, "%s: %d\n", str, val);
105+
char print[1000] = {0};
106+
MEMCPY(print, str, strlen(str));
107+
MEMCPY(print + strlen(str), ": ", 2);
108+
MEMCPY(print + strlen(str) + 2, &val, sizeof(val));
109+
ZEMU_LOGF(100, "%s\n", print);
91110
#else
92111
printf("%s: %d\n", str, val);
93112
#endif
94113
}
95114

96115
void print_u32(const char *str, uint32_t val) {
97116
#if defined(LEDGER_SPECIFIC)
98-
ZEMU_LOGF(100, "%s: %d\n", str, val);
117+
char print[1000] = {0};
118+
MEMCPY(print, str, strlen(str));
119+
MEMCPY(print + strlen(str), ": ", 2);
120+
MEMCPY(print + strlen(str) + 2, &val, sizeof(val));
121+
ZEMU_LOGF(100, "%s\n", print);
99122
#else
100123
printf("%s: %u\n", str, val);
101124
#endif
102125
}
103126

104127
void print_u64(const char *str, uint64_t val) {
105128
#if defined(LEDGER_SPECIFIC)
106-
ZEMU_LOGF(100, "%s: %lu\n", str, val);
129+
char print[1000] = {0};
130+
MEMCPY(print, str, strlen(str));
131+
MEMCPY(print + strlen(str), ": ", 2);
132+
MEMCPY(print + strlen(str) + 2, &val, sizeof(val));
133+
ZEMU_LOGF(100, "%s\n", print);
107134
#else
108135
printf("%s: %llu\n", str, val);
109136
#endif
110137
}
111138

112139
void print_u64_hex(const char *str, uint64_t val) {
113140
#if defined(LEDGER_SPECIFIC)
114-
ZEMU_LOGF(100, "%s: %lu\n", str, val);
141+
char print[1000] = {0};
142+
MEMCPY(print, str, strlen(str));
143+
MEMCPY(print + strlen(str), ": ", 2);
144+
MEMCPY(print + strlen(str) + 2, &val, sizeof(val));
145+
ZEMU_LOGF(100, "%s\n", print);
115146
#else
116147
printf("%s: 0x%llx\n", str, val);
117148
#endif

app/src/parser.c

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -86,8 +86,8 @@ static parser_error_t checkSanity(uint8_t numItems, uint8_t displayIdx) {
8686
return parser_ok;
8787
}
8888

89-
parser_error_t page_title(const parser_tx_t *txObj, char *outKey, uint16_t outKeyLen, const char *title,
90-
primitive_t *primitive, parser_context_t *data_context) {
89+
parser_error_t page_title(parser_tx_t *txObj, char *outKey, uint16_t outKeyLen, const char *title, primitive_t *primitive,
90+
parser_context_t *data_context) {
9191
CHECK_INPUT(outKey);
9292
CHECK_INPUT(title);
9393

@@ -130,8 +130,8 @@ static uint8_t calculate_page_count(const char *text, uint16_t maxCharsPerPage)
130130
return pageCount;
131131
}
132132

133-
parser_error_t page_item(const parser_tx_t *txObj, char *outValue, uint16_t outValueLen, const char *title,
134-
primitive_t *primitive, parser_context_t *data_context, uint8_t pageIdx, uint8_t *pageCount) {
133+
parser_error_t page_item(parser_tx_t *txObj, char *outValue, uint16_t outValueLen, const char *title, primitive_t *primitive,
134+
parser_context_t *data_context, uint8_t pageIdx, uint8_t *pageCount) {
135135
CHECK_INPUT(outValue);
136136
CHECK_INPUT(title);
137137
CHECK_INPUT(primitive);
@@ -176,7 +176,7 @@ parser_error_t page_item(const parser_tx_t *txObj, char *outValue, uint16_t outV
176176
data_context->offset = 0;
177177
page_count_content = calculate_page_count(ui_data_buffer, outValueLen);
178178

179-
uint16_t aux = 0;
179+
uint8_t aux = 0;
180180
if (pageIdx < page_count_title) {
181181
pageString(outValue, outValueLen, ui_buffer, pageIdx, &aux);
182182
} else {
@@ -199,12 +199,12 @@ parser_error_t parser_getItem(const parser_tx_t *txObj, uint8_t displayIdx, char
199199
CHECK_ERROR(checkSanity(numItems, displayIdx))
200200
cleanOutput(outKey, outKeyLen, outVal, outValLen);
201201

202-
CHECK_ERROR(page_title(txObj, outKey, outKeyLen, txObj->ui_items_new.items[displayIdx].title,
203-
&txObj->ui_items_new.items[displayIdx].primitive,
204-
&txObj->ui_items_new.items[displayIdx].data_context))
205-
CHECK_ERROR(page_item(txObj, outVal, outValLen, txObj->ui_items_new.items[displayIdx].title,
206-
&txObj->ui_items_new.items[displayIdx].primitive,
207-
&txObj->ui_items_new.items[displayIdx].data_context, pageIdx, pageCount))
202+
CHECK_ERROR(page_title((parser_tx_t *)txObj, outKey, outKeyLen, txObj->ui_items_new.items[displayIdx].title,
203+
(primitive_t *)&txObj->ui_items_new.items[displayIdx].primitive,
204+
(parser_context_t *)&txObj->ui_items_new.items[displayIdx].data_context))
205+
CHECK_ERROR(page_item((parser_tx_t *)txObj, outVal, outValLen, txObj->ui_items_new.items[displayIdx].title,
206+
(primitive_t *)&txObj->ui_items_new.items[displayIdx].primitive,
207+
(parser_context_t *)&txObj->ui_items_new.items[displayIdx].data_context, pageIdx, pageCount))
208208

209209
return parser_ok;
210210
}

0 commit comments

Comments
 (0)