Merge pull request #11183 from daleckystepan/cppcheck-bugfixes
Fix bugs found by cppcheck
This commit is contained in:
commit
cc45f27fc4
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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';
|
||||
|
||||
|
|
|
@ -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;
|
||||
|
|
Loading…
Reference in New Issue