Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make Cppcheck happier #11175

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 0 additions & 2 deletions lib/main/MAVLink/mavlink_helpers.h
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,6 @@ MAVLINK_HELPER uint8_t mavlink_parse_char(uint8_t chan, uint8_t c, mavlink_messa

mavlink_message_t* rxmsg = mavlink_get_channel_buffer(chan); ///< The currently decoded message
mavlink_status_t* status = mavlink_get_channel_status(chan); ///< The current decode status
int bufferIndex = 0;

status->msg_received = 0;

Expand Down Expand Up @@ -425,7 +424,6 @@ MAVLINK_HELPER uint8_t mavlink_parse_char(uint8_t chan, uint8_t c, mavlink_messa
break;
}

bufferIndex++;
// If a message has been sucessfully decoded, check index
if (status->msg_received == 1)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ typedef struct _CDC_IF_PROP
uint16_t (*pIf_DeInit) (void);
uint16_t (*pIf_Ctrl) (uint32_t Cmd, uint8_t* Buf, uint32_t Len);
uint16_t (*pIf_DataTx) (const uint8_t* Buf, uint32_t Len);
uint16_t (*pIf_DataRx) (uint8_t* Buf, uint32_t Len);
uint16_t (*pIf_DataRx) (const uint8_t* Buf, uint32_t Len);
}
CDC_IF_Prop_TypeDef;
/**
Expand Down
1 change: 1 addition & 0 deletions src/main/build/build_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ typedef enum {
MCU_TYPE_H723_725,
MCU_TYPE_G474,
MCU_TYPE_H730,
MCU_TYPE_LAST,
MCU_TYPE_UNKNOWN = 255,
} mcuTypeId_e;

Expand Down
38 changes: 17 additions & 21 deletions src/main/cli/cli.c
Original file line number Diff line number Diff line change
Expand Up @@ -1086,7 +1086,7 @@ static void cliRxFailsafe(const char *cmdName, char *cmdline)

const rxFailsafeChannelType_e type = (channel < NON_AUX_CHANNEL_COUNT) ? RX_FAILSAFE_TYPE_FLIGHT : RX_FAILSAFE_TYPE_AUX;
rxFailsafeChannelMode_e mode = channelFailsafeConfig->mode;
bool requireValue = channelFailsafeConfig->mode == RX_FAILSAFE_MODE_SET;
bool requireValue = mode == RX_FAILSAFE_MODE_SET;

ptr = nextArg(ptr);
if (ptr) {
Expand Down Expand Up @@ -1649,28 +1649,26 @@ static void printAdjustmentRange(dumpFlags_t dumpMask, const adjustmentRange_t *
static void cliAdjustmentRange(const char *cmdName, char *cmdline)
{
const char *format = "adjrange %u 0 %u %u %u %u %u %u %u";
int i, val = 0;
const char *ptr;

if (isEmpty(cmdline)) {
printAdjustmentRange(DUMP_MASTER, adjustmentRanges(0), NULL, NULL);
} else {
ptr = cmdline;
i = atoi(ptr++);
int i = atoi(ptr++);
if (i < MAX_ADJUSTMENT_RANGE_COUNT) {
adjustmentRange_t *ar = adjustmentRangesMutable(i);
uint8_t validArgumentCount = 0;

ptr = nextArg(ptr);
if (ptr) {
val = atoi(ptr);
// Was: slot
// Keeping the parameter to retain backwards compatibility for the command format.
validArgumentCount++;
}
ptr = nextArg(ptr);
if (ptr) {
val = atoi(ptr);
int val = atoi(ptr);
if (val >= 0 && val < MAX_AUX_CHANNEL_COUNT) {
ar->auxChannelIndex = val;
validArgumentCount++;
Expand All @@ -1681,15 +1679,15 @@ static void cliAdjustmentRange(const char *cmdName, char *cmdline)

ptr = nextArg(ptr);
if (ptr) {
val = atoi(ptr);
int val = atoi(ptr);
if (val >= 0 && val < ADJUSTMENT_FUNCTION_COUNT) {
ar->adjustmentConfig = val;
validArgumentCount++;
}
}
ptr = nextArg(ptr);
if (ptr) {
val = atoi(ptr);
int val = atoi(ptr);
if (val >= 0 && val < MAX_AUX_CHANNEL_COUNT) {
ar->auxSwitchChannelIndex = val;
validArgumentCount++;
Expand All @@ -1708,13 +1706,13 @@ static void cliAdjustmentRange(const char *cmdName, char *cmdline)

ptr = nextArg(ptr);
if (ptr) {
val = atoi(ptr);
int val = atoi(ptr);
ar->adjustmentCenter = val;
validArgumentCount++;
}
ptr = nextArg(ptr);
if (ptr) {
val = atoi(ptr);
int val = atoi(ptr);
ar->adjustmentScale = val;
validArgumentCount++;
}
Expand Down Expand Up @@ -2631,7 +2629,6 @@ static void printVtx(dumpFlags_t dumpMask, const vtxConfig_t *vtxConfig, const v
static void cliVtx(const char *cmdName, char *cmdline)
{
const char *format = "vtx %u %u %u %u %u %u %u";
int i, val = 0;
const char *ptr;

if (isEmpty(cmdline)) {
Expand All @@ -2647,37 +2644,37 @@ static void cliVtx(const char *cmdName, char *cmdline)
const uint8_t maxPowerIndex = VTX_TABLE_MAX_POWER_LEVELS;
#endif
ptr = cmdline;
i = atoi(ptr++);
int i = atoi(ptr++);
if (i < MAX_CHANNEL_ACTIVATION_CONDITION_COUNT) {
vtxChannelActivationCondition_t *cac = &vtxConfigMutable()->vtxChannelActivationConditions[i];
uint8_t validArgumentCount = 0;
ptr = nextArg(ptr);
if (ptr) {
val = atoi(ptr);
int val = atoi(ptr);
if (val >= 0 && val < MAX_AUX_CHANNEL_COUNT) {
cac->auxChannelIndex = val;
validArgumentCount++;
}
}
ptr = nextArg(ptr);
if (ptr) {
val = atoi(ptr);
int val = atoi(ptr);
if (val >= 0 && val <= maxBandIndex) {
cac->band = val;
validArgumentCount++;
}
}
ptr = nextArg(ptr);
if (ptr) {
val = atoi(ptr);
int val = atoi(ptr);
if (val >= 0 && val <= maxChannelIndex) {
cac->channel = val;
validArgumentCount++;
}
}
ptr = nextArg(ptr);
if (ptr) {
val = atoi(ptr);
int val = atoi(ptr);
if (val >= 0 && val <= maxPowerIndex) {
cac->power= val;
validArgumentCount++;
Expand Down Expand Up @@ -4514,7 +4511,7 @@ STATIC_UNIT_TESTED void cliGet(const char *cmdName, char *cmdline)
}
}

static uint8_t getWordLength(char *bufBegin, char *bufEnd)
static uint8_t getWordLength(const char *bufBegin, char *bufEnd)
{
while (*(bufEnd - 1) == ' ') {
bufEnd--;
Expand Down Expand Up @@ -4729,7 +4726,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 < MCU_TYPE_LAST) {
return mcuTypeNames[id];
} else {
return "UNKNOWN";
Expand Down Expand Up @@ -5252,7 +5249,7 @@ static void printResource(dumpFlags_t dumpMask, const char *headingStr)

for (int index = 0; index < RESOURCE_VALUE_MAX_INDEX(resourceTable[i].maxIndex); index++) {
const ioTag_t ioTag = *(ioTag_t *)((const uint8_t *)currentConfig + resourceTable[i].stride * index + resourceTable[i].offset);
ioTag_t ioTagDefault = NULL;
ioTag_t ioTagDefault = 0;
if (defaultConfig) {
ioTagDefault = *(ioTag_t *)((const uint8_t *)defaultConfig + resourceTable[i].stride * index + resourceTable[i].offset);
}
Expand Down Expand Up @@ -5523,9 +5520,8 @@ static void printTimerDmaoptDetails(const ioTag_t ioTag, const timerHardware_t *

if (printDetails) {
const dmaChannelSpec_t *dmaChannelSpec = dmaGetChannelSpecByTimerValue(timer->tim, timer->channel, dmaopt);
dmaCode_t dmaCode = 0;
if (dmaChannelSpec) {
dmaCode = dmaChannelSpec->code;
dmaCode_t dmaCode = dmaChannelSpec->code;
printValue(dumpMask, false,
"# pin %c%02d: " DMASPEC_FORMAT_STRING,
IO_GPIOPortIdxByTag(ioTag) + 'A', IO_GPIOPinIdxByTag(ioTag),
Expand Down Expand Up @@ -5664,7 +5660,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;
Expand Down
2 changes: 1 addition & 1 deletion src/main/cms/cms.c
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ static displayPort_t *cmsDisplayPortSelectNext(void)
return cmsDisplayPorts[cmsCurrentDevice];
}

bool cmsDisplayPortSelect(displayPort_t *instance)
bool cmsDisplayPortSelect(const displayPort_t *instance)
{
for (unsigned i = 0; i < cmsDeviceCount; i++) {
if (cmsDisplayPortSelectNext() == instance) {
Expand Down
2 changes: 1 addition & 1 deletion src/main/cms/cms.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ extern displayPort_t *pCurrentDisplay;
void cmsInit(void);
void cmsHandler(timeUs_t currentTimeUs);

bool cmsDisplayPortSelect(displayPort_t *instance);
bool cmsDisplayPortSelect(const displayPort_t *instance);
void cmsMenuOpen(void);
const void *cmsMenuChange(displayPort_t *pPort, const void *ptr);
const void *cmsMenuExit(displayPort_t *pPort, const void *ptr);
Expand Down
18 changes: 9 additions & 9 deletions src/main/common/maths.c
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ void applyMatrixRotation(float *v, fp_rotationMatrix_t *rotationMatrix)
#define QMF_SORTF(a,b) { if ((a)>(b)) QMF_SWAPF((a),(b)); }
#define QMF_SWAPF(a,b) { float temp=(a);(a)=(b);(b)=temp; }

int32_t quickMedianFilter3(int32_t * v)
int32_t quickMedianFilter3(const int32_t * v)
{
int32_t p[3];
QMF_COPY(p, v, 3);
Expand All @@ -235,7 +235,7 @@ int32_t quickMedianFilter3(int32_t * v)
return p[1];
}

int32_t quickMedianFilter5(int32_t * v)
int32_t quickMedianFilter5(const int32_t * v)
{
int32_t p[5];
QMF_COPY(p, v, 5);
Expand All @@ -246,7 +246,7 @@ int32_t quickMedianFilter5(int32_t * v)
return p[2];
}

int32_t quickMedianFilter7(int32_t * v)
int32_t quickMedianFilter7(const int32_t * v)
{
int32_t p[7];
QMF_COPY(p, v, 7);
Expand All @@ -259,7 +259,7 @@ int32_t quickMedianFilter7(int32_t * v)
return p[3];
}

int32_t quickMedianFilter9(int32_t * v)
int32_t quickMedianFilter9(const int32_t * v)
{
int32_t p[9];
QMF_COPY(p, v, 9);
Expand All @@ -274,7 +274,7 @@ int32_t quickMedianFilter9(int32_t * v)
return p[4];
}

float quickMedianFilter3f(float * v)
float quickMedianFilter3f(const float * v)
{
float p[3];
QMF_COPY(p, v, 3);
Expand All @@ -283,7 +283,7 @@ float quickMedianFilter3f(float * v)
return p[1];
}

float quickMedianFilter5f(float * v)
float quickMedianFilter5f(const float * v)
{
float p[5];
QMF_COPY(p, v, 5);
Expand All @@ -294,7 +294,7 @@ float quickMedianFilter5f(float * v)
return p[2];
}

float quickMedianFilter7f(float * v)
float quickMedianFilter7f(const float * v)
{
float p[7];
QMF_COPY(p, v, 7);
Expand All @@ -307,7 +307,7 @@ float quickMedianFilter7f(float * v)
return p[3];
}

float quickMedianFilter9f(float * v)
float quickMedianFilter9f(const float * v)
{
float p[9];
QMF_COPY(p, v, 9);
Expand All @@ -322,7 +322,7 @@ float quickMedianFilter9f(float * v)
return p[4];
}

void arraySubInt32(int32_t *dest, int32_t *array1, int32_t *array2, int count)
void arraySubInt32(int32_t *dest, const int32_t *array1, const int32_t *array2, int count)
{
for (int i = 0; i < count; i++) {
dest[i] = array1[i] - array2[i];
Expand Down
18 changes: 9 additions & 9 deletions src/main/common/maths.h
Original file line number Diff line number Diff line change
Expand Up @@ -114,15 +114,15 @@ float scaleRangef(float x, float srcFrom, float srcTo, float destFrom, float des
void buildRotationMatrix(fp_angles_t *delta, fp_rotationMatrix_t *rotation);
void applyMatrixRotation(float *v, fp_rotationMatrix_t *rotationMatrix);

int32_t quickMedianFilter3(int32_t * v);
int32_t quickMedianFilter5(int32_t * v);
int32_t quickMedianFilter7(int32_t * v);
int32_t quickMedianFilter9(int32_t * v);
int32_t quickMedianFilter3(const int32_t * v);
int32_t quickMedianFilter5(const int32_t * v);
int32_t quickMedianFilter7(const int32_t * v);
int32_t quickMedianFilter9(const int32_t * v);

float quickMedianFilter3f(float * v);
float quickMedianFilter5f(float * v);
float quickMedianFilter7f(float * v);
float quickMedianFilter9f(float * v);
float quickMedianFilter3f(const float * v);
float quickMedianFilter5f(const float * v);
float quickMedianFilter7f(const float * v);
float quickMedianFilter9f(const float * v);

#if defined(FAST_MATH) || defined(VERY_FAST_MATH)
float sin_approx(float x);
Expand All @@ -144,7 +144,7 @@ float pow_approx(float a, float b);
#define pow_approx(a, b) powf(b, a)
#endif

void arraySubInt32(int32_t *dest, int32_t *array1, int32_t *array2, int count);
void arraySubInt32(int32_t *dest, const int32_t *array1, const int32_t *array2, int count);

int16_t qPercent(fix12_t q);
int16_t qMultiply(fix12_t q, int16_t input);
Expand Down
3 changes: 1 addition & 2 deletions src/main/common/sdft.c
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,8 @@ void sdftInit(sdft_t *sdft, const int startBin, const int endBin, const int numB
if (!isInitialized) {
rPowerN = powf(SDFT_R, SDFT_SAMPLE_SIZE);
const float c = 2.0f * M_PIf / (float)SDFT_SAMPLE_SIZE;
float phi = 0.0f;
for (int i = 0; i < SDFT_BIN_COUNT; i++) {
phi = c * i;
float phi = c * i;
twiddle[i] = SDFT_R * (cos_approx(phi) + _Complex_I * sin_approx(phi));
}
isInitialized = true;
Expand Down
6 changes: 3 additions & 3 deletions src/main/common/time.c
Original file line number Diff line number Diff line change
Expand Up @@ -183,12 +183,12 @@ rtcTime_t rtcTimeMake(int32_t secs, uint16_t millis)
return ((rtcTime_t)secs) * MILLIS_PER_SECOND + millis;
}

int32_t rtcTimeGetSeconds(rtcTime_t *t)
int32_t rtcTimeGetSeconds(const rtcTime_t *t)
{
return *t / MILLIS_PER_SECOND;
}

uint16_t rtcTimeGetMillis(rtcTime_t *t)
uint16_t rtcTimeGetMillis(const rtcTime_t *t)
{
return *t % MILLIS_PER_SECOND;
}
Expand Down Expand Up @@ -243,7 +243,7 @@ bool rtcGet(rtcTime_t *t)
return true;
}

bool rtcSet(rtcTime_t *t)
bool rtcSet(const rtcTime_t *t)
{
started = *t - millis();
return true;
Expand Down
6 changes: 3 additions & 3 deletions src/main/common/time.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,8 @@ PG_DECLARE(timeConfig_t, timeConfig);
typedef int64_t rtcTime_t;

rtcTime_t rtcTimeMake(int32_t secs, uint16_t millis);
int32_t rtcTimeGetSeconds(rtcTime_t *t);
uint16_t rtcTimeGetMillis(rtcTime_t *t);
int32_t rtcTimeGetSeconds(const rtcTime_t *t);
uint16_t rtcTimeGetMillis(const rtcTime_t *t);

typedef struct _dateTime_s {
// full year
Expand Down Expand Up @@ -94,7 +94,7 @@ bool dateTimeSplitFormatted(char *formatted, char **date, char **time);
bool rtcHasTime(void);

bool rtcGet(rtcTime_t *t);
bool rtcSet(rtcTime_t *t);
bool rtcSet(const rtcTime_t *t);

bool rtcGetDateTime(dateTime_t *dt);
bool rtcSetDateTime(dateTime_t *dt);
Expand Down