diff --git a/src/main/cli/cli.c b/src/main/cli/cli.c index a11b1394a9..e8a919a520 100644 --- a/src/main/cli/cli.c +++ b/src/main/cli/cli.c @@ -4729,7 +4729,7 @@ STATIC_UNIT_TESTED void cliSet(const char *cmdName, char *cmdline) static const char *getMcuTypeById(mcuTypeId_e id) { - if (id < MCU_TYPE_UNKNOWN) { + if (id < ARRAYLEN(mcuTypeNames)) { return mcuTypeNames[id]; } else { return "UNKNOWN"; @@ -5664,7 +5664,7 @@ static void cliDmaopt(const char *cmdName, char *cmdline) const timerHardware_t *timer = NULL; pch = strtok_r(NULL, " ", &saveptr); if (entry) { - index = atoi(pch) - 1; + index = pch ? (atoi(pch) - 1) : -1; if (index < 0 || index >= entry->maxIndex || (entry->presenceMask != MASK_IGNORED && !(entry->presenceMask & BIT(index + 1)))) { cliPrintErrorLinef(cmdName, "BAD INDEX: '%s'", pch ? pch : ""); return; diff --git a/src/main/drivers/bus_i2c_hal.c b/src/main/drivers/bus_i2c_hal.c index 2f55afaba7..612181527e 100644 --- a/src/main/drivers/bus_i2c_hal.c +++ b/src/main/drivers/bus_i2c_hal.c @@ -102,7 +102,7 @@ uint16_t i2cGetErrorCounter(void) // Blocking write bool i2cWrite(I2CDevice device, uint8_t addr_, uint8_t reg_, uint8_t data) { - if (device == I2CINVALID || device > I2CDEV_COUNT) { + if (device == I2CINVALID || device >= I2CDEV_COUNT) { return false; } @@ -128,7 +128,7 @@ bool i2cWrite(I2CDevice device, uint8_t addr_, uint8_t reg_, uint8_t data) // Non-blocking write bool i2cWriteBuffer(I2CDevice device, uint8_t addr_, uint8_t reg_, uint8_t len_, uint8_t *data) { - if (device == I2CINVALID || device > I2CDEV_COUNT) { + if (device == I2CINVALID || device >= I2CDEV_COUNT) { return false; } @@ -157,7 +157,7 @@ bool i2cWriteBuffer(I2CDevice device, uint8_t addr_, uint8_t reg_, uint8_t len_, // Blocking read bool i2cRead(I2CDevice device, uint8_t addr_, uint8_t reg_, uint8_t len, uint8_t* buf) { - if (device == I2CINVALID || device > I2CDEV_COUNT) { + if (device == I2CINVALID || device >= I2CDEV_COUNT) { return false; } @@ -184,7 +184,7 @@ bool i2cRead(I2CDevice device, uint8_t addr_, uint8_t reg_, uint8_t len, uint8_t // Non-blocking read bool i2cReadBuffer(I2CDevice device, uint8_t addr_, uint8_t reg_, uint8_t len, uint8_t* buf) { - if (device == I2CINVALID || device > I2CDEV_COUNT) { + if (device == I2CINVALID || device >= I2CDEV_COUNT) { return false; } diff --git a/src/main/drivers/bus_i2c_stm32f10x.c b/src/main/drivers/bus_i2c_stm32f10x.c index 743e88c539..338e7ef00a 100644 --- a/src/main/drivers/bus_i2c_stm32f10x.c +++ b/src/main/drivers/bus_i2c_stm32f10x.c @@ -165,7 +165,7 @@ static bool i2cHandleHardwareFailure(I2CDevice device) bool i2cWriteBuffer(I2CDevice device, uint8_t addr_, uint8_t reg_, uint8_t len_, uint8_t *data) { - if (device == I2CINVALID || device > I2CDEV_COUNT) { + if (device == I2CINVALID || device >= I2CDEV_COUNT) { return false; } @@ -238,7 +238,7 @@ bool i2cWrite(I2CDevice device, uint8_t addr_, uint8_t reg_, uint8_t data) bool i2cReadBuffer(I2CDevice device, uint8_t addr_, uint8_t reg_, uint8_t len, uint8_t* buf) { - if (device == I2CINVALID || device > I2CDEV_COUNT) { + if (device == I2CINVALID || device >= I2CDEV_COUNT) { return false; } diff --git a/src/main/drivers/bus_i2c_stm32f30x.c b/src/main/drivers/bus_i2c_stm32f30x.c index 54184179be..30a342f8c4 100644 --- a/src/main/drivers/bus_i2c_stm32f30x.c +++ b/src/main/drivers/bus_i2c_stm32f30x.c @@ -80,7 +80,7 @@ uint32_t i2cTimeoutUserCallback(void) void i2cInit(I2CDevice device) { - if (device == I2CINVALID || device > I2CDEV_COUNT) { + if (device == I2CINVALID || device >= I2CDEV_COUNT) { return; } @@ -129,7 +129,7 @@ uint16_t i2cGetErrorCounter(void) bool i2cWrite(I2CDevice device, uint8_t addr_, uint8_t reg, uint8_t data) { - if (device == I2CINVALID || device > I2CDEV_COUNT) { + if (device == I2CINVALID || device >= I2CDEV_COUNT) { return false; } @@ -203,7 +203,7 @@ bool i2cWrite(I2CDevice device, uint8_t addr_, uint8_t reg, uint8_t data) bool i2cRead(I2CDevice device, uint8_t addr_, uint8_t reg, uint8_t len, uint8_t* buf) { - if (device == I2CINVALID || device > I2CDEV_COUNT) { + if (device == I2CINVALID || device >= I2CDEV_COUNT) { return false; } diff --git a/src/main/flight/feedforward.c b/src/main/flight/feedforward.c index 69c42a9a32..698724878d 100644 --- a/src/main/flight/feedforward.c +++ b/src/main/flight/feedforward.c @@ -218,6 +218,6 @@ FAST_CODE_NOINLINE float applyFeedforwardLimit(int axis, float value, float Kp, bool shouldApplyFeedforwardLimits(int axis) { - return feedforwardMaxRateLimit[axis] != 0.0f && axis < FD_YAW; + return axis < FD_YAW && feedforwardMaxRateLimit[axis] != 0.0f; } #endif diff --git a/src/main/io/asyncfatfs/asyncfatfs.c b/src/main/io/asyncfatfs/asyncfatfs.c index 759448849f..13d3760937 100644 --- a/src/main/io/asyncfatfs/asyncfatfs.c +++ b/src/main/io/asyncfatfs/asyncfatfs.c @@ -2294,7 +2294,7 @@ static afatfsOperationStatus_e afatfs_extendSubdirectoryContinue(afatfsFile_t *d } // Seek back to the beginning of the cluster - afatfs_assert(afatfs_fseekAtomic(directory, -AFATFS_SECTOR_SIZE * (afatfs.sectorsPerCluster - 1))); + afatfs_assert(afatfs_fseekAtomic(directory, -AFATFS_SECTOR_SIZE * ((int32_t)afatfs.sectorsPerCluster - 1))); opState->phase = AFATFS_EXTEND_SUBDIRECTORY_PHASE_SUCCESS; goto doMore; break; diff --git a/src/main/msp/msp.c b/src/main/msp/msp.c index 102566fb39..612a4a7dcf 100644 --- a/src/main/msp/msp.c +++ b/src/main/msp/msp.c @@ -3681,6 +3681,7 @@ static mspResult_e mspProcessInCommand(mspDescriptor_t srcDesc, int16_t cmdMSP, sbufReadData(src, boardName, MIN(length, MAX_BOARD_NAME_LENGTH)); if (length > MAX_BOARD_NAME_LENGTH) { sbufAdvance(src, length - MAX_BOARD_NAME_LENGTH); + length = MAX_BOARD_NAME_LENGTH; } boardName[length] = '\0'; length = sbufReadU8(src); @@ -3688,6 +3689,7 @@ static mspResult_e mspProcessInCommand(mspDescriptor_t srcDesc, int16_t cmdMSP, sbufReadData(src, manufacturerId, MIN(length, MAX_MANUFACTURER_ID_LENGTH)); if (length > MAX_MANUFACTURER_ID_LENGTH) { sbufAdvance(src, length - MAX_MANUFACTURER_ID_LENGTH); + length = MAX_MANUFACTURER_ID_LENGTH; } manufacturerId[length] = '\0'; diff --git a/src/main/telemetry/crsf.c b/src/main/telemetry/crsf.c index 1b27f696c4..b64e4f951f 100644 --- a/src/main/telemetry/crsf.c +++ b/src/main/telemetry/crsf.c @@ -493,7 +493,7 @@ static void cRleEncodeStream(sbuf_t *source, sbuf_t *dest, uint8_t maxDestLen) c |= CRSF_RLE_CHAR_REPEATED_MASK; const uint8_t fullBatches = (runLength / CRSF_RLE_MAX_RUN_LENGTH); const uint8_t remainder = (runLength % CRSF_RLE_MAX_RUN_LENGTH); - const uint8_t totalBatches = fullBatches + (remainder) ? 1 : 0; + const uint8_t totalBatches = fullBatches + (remainder ? 1 : 0); if (destRemaining >= totalBatches * CRSF_RLE_BATCH_SIZE) { for (unsigned int i = 1; i <= totalBatches; i++) { const uint8_t batchLength = (i < totalBatches) ? CRSF_RLE_MAX_RUN_LENGTH : remainder;