Skip to content

Commit

Permalink
fix out of range warning (#2299)
Browse files Browse the repository at this point in the history
  • Loading branch information
gullradriel authored Oct 14, 2024
1 parent a223bd1 commit 26b830b
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions firmware/common/i2cdev_ppmod.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,22 @@ std::vector<uint8_t> I2cDev_PPmod::downloadStandaloneApp(uint32_t index, size_t
return {};
}

uint16_t data[3] = {(uint16_t)Command::COMMAND_APP_TRANSFER, (uint16_t)index, (uint16_t)(offset / transfer_block_size)};

uint16_t data[3] = {
static_cast<uint16_t>(Command::COMMAND_APP_TRANSFER),
static_cast<uint16_t>(index & 0xFFFF), // keep index in 16 bits range
static_cast<uint16_t>((offset / transfer_block_size) & 0xFFFF) // keep (offset / transfer_block_size) in 16 bits range
};

/*
// TODO: check if there was an out of range, manage error
if (index > std::numeric_limits<uint16_t>::max()) {
// manage error if index is bigger than a 16 bits value
}
// TODO: check if there was an out of range, manage error
if (offset / transfer_block_size > std::numeric_limits<uint16_t>::max()) {
// manage error if (offset / transfer_block_size ) is bigger than a 16 bits value
}
*/
std::vector<uint8_t> ret(transfer_block_size);
bool success = i2c_read((uint8_t*)&data, sizeof(data), (uint8_t*)ret.data(), transfer_block_size);
if (success == false) {
Expand Down

0 comments on commit 26b830b

Please sign in to comment.