From 26b830b8166a64665ac52e46b551390b0a76fe2c Mon Sep 17 00:00:00 2001 From: gullradriel <3157857+gullradriel@users.noreply.github.com> Date: Mon, 14 Oct 2024 18:26:02 +0200 Subject: [PATCH] fix out of range warning (#2299) --- firmware/common/i2cdev_ppmod.cpp | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/firmware/common/i2cdev_ppmod.cpp b/firmware/common/i2cdev_ppmod.cpp index fb39f1b3c..68b53d75b 100644 --- a/firmware/common/i2cdev_ppmod.cpp +++ b/firmware/common/i2cdev_ppmod.cpp @@ -69,8 +69,22 @@ std::vector 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(Command::COMMAND_APP_TRANSFER), + static_cast(index & 0xFFFF), // keep index in 16 bits range + static_cast((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::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::max()) { + // manage error if (offset / transfer_block_size ) is bigger than a 16 bits value + } + */ std::vector ret(transfer_block_size); bool success = i2c_read((uint8_t*)&data, sizeof(data), (uint8_t*)ret.data(), transfer_block_size); if (success == false) {