Skip to content

Commit a970658

Browse files
BootloaderTest: Fix some signed vs unsigned warnings
These happen on AVR because uint8_t is promoted to int (int16_t), not unsigned (uint16_t) and then compared with uint16_t (MAX_MSG_LEN). On ARM, this probaly does not happen because both are promoted to int, which is int32_t there.
1 parent 2b99d63 commit a970658

1 file changed

Lines changed: 7 additions & 7 deletions

File tree

BootloaderTest/BootloaderTest.ino

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ void printHexBuf(uint8_t *buf, size_t len) {
143143

144144
#if defined(USE_I2C)
145145
bool write_command(uint8_t cmd, uint8_t *dataout, uint8_t len, uint8_t crc_xor = 0) {
146-
assertLessOrEqual(len + 2, MAX_MSG_LEN, "", false);
146+
assertLessOrEqual((uint16_t)len + 2, MAX_MSG_LEN, "", false);
147147
assertAck(bus.startWrite(cfg.curAddr),"", false);
148148
assertAck(bus.llWrite(cmd), "", false);
149149
for (uint8_t i = 0; i < len; ++i)
@@ -158,8 +158,8 @@ void printHexBuf(uint8_t *buf, size_t len) {
158158
}
159159

160160
bool read_status(uint8_t *status, uint8_t *datain, ReadLen okLen, ReadLen failLen, uint8_t *actualLen = nullptr, bool skip_start = false) {
161-
assertLessOrEqual(okLen.len + 3, MAX_MSG_LEN, "", false);
162-
assertLessOrEqual(failLen.len + 3, MAX_MSG_LEN, "", false);
161+
assertLessOrEqual((uint16_t)okLen.len + 3, MAX_MSG_LEN, "", false);
162+
assertLessOrEqual((uint16_t)failLen.len + 3, MAX_MSG_LEN, "", false);
163163
if (!skip_start) {
164164
assertAck(bus.startRead(cfg.curAddr), "", false);
165165
}
@@ -199,7 +199,7 @@ void printHexBuf(uint8_t *buf, size_t len) {
199199
}
200200
#elif defined(USE_RS485)
201201
bool write_command(uint8_t cmd, uint8_t *dataout, uint8_t len, uint8_t crc_xor = 0) {
202-
assertLessOrEqual(len + 2, MAX_MSG_LEN, "", false);
202+
assertLessOrEqual((uint16_t)len + 2, MAX_MSG_LEN, "", false);
203203
assertEqual(bus.read(), -1, F("pending data at start of command"), false);
204204
digitalWrite(RS485_DE_PIN, HIGH);
205205
bus.write(cfg.curAddr);
@@ -259,8 +259,8 @@ void printHexBuf(uint8_t *buf, size_t len) {
259259
}
260260

261261
bool read_status(uint8_t *status, uint8_t *datain, ReadLen okLen, ReadLen failLen, uint8_t *actualLen = nullptr, bool skip_start = false) {
262-
assertLessOrEqual(okLen.len + 3, MAX_MSG_LEN, "", false);
263-
assertLessOrEqual(failLen.len + 3, MAX_MSG_LEN, "", false);
262+
assertLessOrEqual((uint16_t)okLen.len + 3, MAX_MSG_LEN, "", false);
263+
assertLessOrEqual((uint16_t)failLen.len + 3, MAX_MSG_LEN, "", false);
264264

265265
uint8_t addr;
266266
assertTrue(read_byte(&addr, MAX_RESPONSE_TIME), F("timeout waiting for response"), false);
@@ -944,7 +944,7 @@ test(095_get_max_packet_length) {
944944
uint8_t data[2];
945945
assertTrue(run_transaction_ok(Commands::GET_MAX_PACKET_LENGTH, nullptr, 0, data, READ_EXACTLY(sizeof(data))));
946946

947-
assertEqual(data[0] << 8 | data[1], MAX_MSG_LEN);
947+
assertEqual((uint16_t)data[0] << 8 | data[1], MAX_MSG_LEN);
948948
} else {
949949
assertTrue(check_command_not_supported(Commands::GET_MAX_PACKET_LENGTH));
950950
}

0 commit comments

Comments
 (0)