Skip to content

Commit e6696ce

Browse files
committed
fix compiler warnings
1 parent e9ef016 commit e6696ce

File tree

6 files changed

+31
-31
lines changed

6 files changed

+31
-31
lines changed

seedtool/seed.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,8 @@ class SLIP39ShareSeq {
7171
static bool verify_share_checksum(uint16_t const * share);
7272

7373
static SLIP39ShareSeq * from_seed(Seed const * seed,
74-
size_t thresh,
75-
size_t nshares,
74+
uint8_t thresh,
75+
uint8_t nshares,
7676
void(*randgen)(uint8_t *, size_t));
7777

7878
// Read-only, don't free returned value.

seedtool/seed.ino

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,8 @@ Seed::Seed(uint8_t const * i_data, size_t len) {
3535

3636
void Seed::log() const {
3737
serial_printf("seed: ");
38-
for (int ii = 0; ii < sizeof(data); ++ii)
39-
serial_printf("%02x", (int) data[ii]);
38+
for (size_t ii = 0; ii < sizeof(data); ++ii)
39+
serial_printf("%02x", data[ii]);
4040
serial_printf("\n");
4141
}
4242

@@ -65,10 +65,10 @@ bool SLIP39ShareSeq::verify_share_checksum(uint16_t const * share) {
6565
}
6666

6767
SLIP39ShareSeq * SLIP39ShareSeq::from_seed(Seed const * seed,
68-
size_t thresh,
69-
size_t nshares,
68+
uint8_t thresh,
69+
uint8_t nshares,
7070
void(*randgen)(uint8_t *, size_t)) {
71-
char * password = "";
71+
const char * password = "";
7272
uint8_t group_threshold = 1;
7373
uint8_t group_count = 1;
7474
group_descriptor group = { thresh, nshares, NULL };
@@ -91,7 +91,7 @@ SLIP39ShareSeq * SLIP39ShareSeq::from_seed(Seed const * seed,
9191
shares_buffer,
9292
shares_buffer_size,
9393
randgen);
94-
serial_assert(rv == nshares);
94+
serial_assert(rv == (int)nshares);
9595
serial_assert(words_in_each_share == WORDS_PER_SHARE);
9696

9797
SLIP39ShareSeq * slip39 = new SLIP39ShareSeq();
@@ -101,7 +101,7 @@ SLIP39ShareSeq * SLIP39ShareSeq::from_seed(Seed const * seed,
101101
}
102102

103103
char const * SLIP39ShareSeq::error_msg(int errval) {
104-
char buffer[1024];
104+
static char buffer[1024];
105105
switch (errval) {
106106
// max message size 18 chars |----------------|
107107
case ERROR_INVALID_SHARD_SET: return "Invalid shard set";
@@ -169,7 +169,7 @@ char const * SLIP39ShareSeq::get_share_word(size_t sndx, size_t wndx) const {
169169

170170
Seed * SLIP39ShareSeq::restore_seed() const {
171171
uint8_t seed_data[Seed::SIZE];
172-
char * password = "";
172+
const char * password = "";
173173
last_rv = slip39_combine(const_cast<const uint16_t **>(shares),
174174
WORDS_PER_SHARE,
175175
nshares,

seedtool/selftest.ino

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ uint16_t ref_bip39_words_bad_checksum[BIP39Seq::WORD_COUNT] =
3030
0x0494, 0x0039, 0x050d, 0x04f1
3131
};
3232

33-
char* ref_bip39_mnemonics[BIP39Seq::WORD_COUNT] =
33+
const char* ref_bip39_mnemonics[BIP39Seq::WORD_COUNT] =
3434
{
3535
"mirror", "reject", "rookie", "talk",
3636
"pudding", "throw", "happy", "era",
@@ -39,7 +39,7 @@ char* ref_bip39_mnemonics[BIP39Seq::WORD_COUNT] =
3939

4040
size_t const ref_slip39_thresh = 2;
4141
size_t const ref_slip39_nshares = 3;
42-
char* ref_slip39_shares[ref_slip39_nshares] =
42+
const char* ref_slip39_shares[ref_slip39_nshares] =
4343
{
4444
"check academic academic acid counter "
4545
"both course legs visitor squeeze "
@@ -77,7 +77,7 @@ uint16_t ref_slip39_words[ref_slip39_nshares][SLIP39ShareSeq::WORDS_PER_SHARE] =
7777

7878
// These shares are *also* generated from seed="123456", but they use
7979
// a different random seed so they are not compatible with the others.
80-
char* ref_slip39_shares_alt[ref_slip39_nshares] =
80+
const char* ref_slip39_shares_alt[ref_slip39_nshares] =
8181
{
8282
"deny category academic acid buyer "
8383
"miracle game discuss hobo decision "
@@ -125,13 +125,13 @@ uint16_t ref_slip39_share_bad_checksum[SLIP39ShareSeq::WORDS_PER_SHARE] =
125125
// Clearly not random. Only use for tests.
126126
void fake_random(uint8_t *buf, size_t count) {
127127
uint8_t b = 0;
128-
for(int i = 0; i < count; i++) {
128+
for(size_t i = 0; i < count; i++) {
129129
buf[i] = b;
130130
b = b + 17;
131131
}
132132
}
133133

134-
bool test_failed(char *format, ...) {
134+
bool test_failed(const char *format, ...) {
135135
char buff[8192];
136136
va_list args;
137137
va_start(args, format);
@@ -470,5 +470,5 @@ String selftest_testname(size_t ndx) {
470470
bool selftest_testrun(size_t ndx) {
471471
using namespace selftest_internal;
472472
serial_assert(ndx < g_numtests);
473-
g_selftests[ndx].testfun();
473+
return g_selftests[ndx].testfun();
474474
}

seedtool/userinterface.ino

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ void full_window_clear() {
5959
while (g_display.nextPage());
6060
}
6161

62-
void display_printf(char *format, ...) {
62+
void display_printf(const char *format, ...) {
6363
char buff[1024];
6464
va_list args;
6565
va_start(args, format);
@@ -129,7 +129,7 @@ void self_test() {
129129
size_t numtests = selftest_numtests();
130130
// Loop, once for each test. Need an extra trip at the end in
131131
// case we failed the last test.
132-
for (int ndx = 0; ndx < numtests+1; ++ndx) {
132+
for (size_t ndx = 0; ndx < numtests+1; ++ndx) {
133133

134134
// If any key is pressed, skip remaining self test.
135135
if (g_keypad.getKey() != NO_KEY)
@@ -718,7 +718,7 @@ void display_slip39() {
718718
yy = Y_MAX - (H_FSB9) + 2;
719719
g_display.setFont(&FreeSansBold9pt7b);
720720
g_display.setCursor(xx, yy);
721-
if (sharendx < (g_slip39_generate->numshares()-1))
721+
if (sharendx < (int)(g_slip39_generate->numshares()-1))
722722
g_display.println("1,7-Up,Down #-Next");
723723
else
724724
g_display.println("1,7-Up,Down #-Done");
@@ -746,7 +746,7 @@ void display_slip39() {
746746
}
747747
break;
748748
case '#': // next / done
749-
if (sharendx < (g_slip39_generate->numshares()-1)) {
749+
if (sharendx < (int)(g_slip39_generate->numshares()-1)) {
750750
++sharendx;
751751
scroll = 0;
752752
} else {
@@ -829,7 +829,7 @@ struct WordListState {
829829
}
830830

831831
void cursor_right() {
832-
if (pos < strlen(refword(wordndx[selected])) - 1)
832+
if (pos < (int)strlen(refword(wordndx[selected])) - 1)
833833
++pos;
834834
}
835835

@@ -1035,7 +1035,7 @@ void restore_bip39() {
10351035
case '#': // done
10361036
{
10371037
uint16_t bip39_words[BIP39Seq::WORD_COUNT];
1038-
for (int ii = 0; ii < BIP39Seq::WORD_COUNT; ++ii)
1038+
for (size_t ii = 0; ii < BIP39Seq::WORD_COUNT; ++ii)
10391039
bip39_words[ii] = state.wordndx[ii];
10401040
BIP39Seq * bip39 = BIP39Seq::from_words(bip39_words);
10411041
Seed * seed = bip39->restore_seed();
@@ -1090,7 +1090,7 @@ void restore_slip39() {
10901090
// Adjust the scroll to center the selection.
10911091
if (selected < 2)
10921092
scroll = 0;
1093-
else if (selected > g_slip39_restore->numshares())
1093+
else if (selected > (int)g_slip39_restore->numshares())
10941094
scroll = g_slip39_restore->numshares() + 2 - disprows;
10951095
else
10961096
scroll = selected - 2;
@@ -1117,9 +1117,9 @@ void restore_slip39() {
11171117
for (int rr = 0; rr < disprows; ++rr) {
11181118
int sharendx = scroll + rr;
11191119
char buffer[32];
1120-
if (sharendx < g_slip39_restore->numshares()) {
1120+
if (sharendx < (int)g_slip39_restore->numshares()) {
11211121
sprintf(buffer, "Share %d", sharendx+1);
1122-
} else if (sharendx == g_slip39_restore->numshares()) {
1122+
} else if (sharendx == (int)g_slip39_restore->numshares()) {
11231123
sprintf(buffer, "Add Share");
11241124
} else {
11251125
sprintf(buffer, "Restore");
@@ -1162,19 +1162,19 @@ void restore_slip39() {
11621162
selected -= 1;
11631163
break;
11641164
case '7':
1165-
if (selected < g_slip39_restore->numshares() + 1 + showrestore - 1)
1165+
if (selected < (int)g_slip39_restore->numshares() + 1 + showrestore - 1)
11661166
selected += 1;
11671167
break;
11681168
case '*':
11691169
g_uistate = SEEDLESS_MENU;
11701170
return;
11711171
case '#':
1172-
if (selected < g_slip39_restore->numshares()) {
1172+
if (selected < (int)g_slip39_restore->numshares()) {
11731173
// Edit existing share
11741174
g_restore_slip39_selected = selected;
11751175
g_uistate = ENTER_SHARE;
11761176
return;
1177-
} else if (selected == g_slip39_restore->numshares()) {
1177+
} else if (selected == (int)g_slip39_restore->numshares()) {
11781178
// Add new (zeroed) share
11791179
uint16_t share[SLIP39ShareSeq::WORDS_PER_SHARE] =
11801180
{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
@@ -1190,7 +1190,7 @@ void restore_slip39() {
11901190
// happening ..
11911191
full_window_clear();
11921192

1193-
for (int ii = 0; ii < g_slip39_restore->numshares(); ++ii) {
1193+
for (size_t ii = 0; ii < g_slip39_restore->numshares(); ++ii) {
11941194
char * strings =
11951195
g_slip39_restore->get_share_strings(ii);
11961196
serial_printf("%d %s\n", ii+1, strings);

seedtool/util.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
#ifndef _UTIL_H
44
#define _UTIL_H
55

6-
void serial_printf(char *format, ...);
6+
void serial_printf(const char *format, ...);
77

88
#define serial_assert(_exp) \
99
do { \

seedtool/util.ino

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
#include "util.h"
44

5-
void serial_printf(char *format, ...) {
5+
void serial_printf(const char *format, ...) {
66
char buff[1024];
77
va_list args;
88
va_start(args, format);

0 commit comments

Comments
 (0)