Skip to content

Commit ef152ae

Browse files
authored
Merge pull request #3334
Fix various problems and bugs detected by cppcheck
2 parents a4c72e9 + 3a95ea0 commit ef152ae

22 files changed

Lines changed: 64 additions & 56 deletions

File tree

src/emc/canterp/canterp.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -586,7 +586,7 @@ int Canterp::execute(const char *line) {
586586
}
587587

588588
if (!strcmp(the_command_name, "ORIENT_SPINDLE")) {
589-
if (3 != sscanf(the_command_args, "%d %lf %s", &i1, &d1, s1)) {
589+
if (3 != sscanf(the_command_args, "%d %lf %255s", &i1, &d1, s1)) {
590590
return INTERP_ERROR;
591591
}
592592
if (!strcmp(s1, "CANON_CLOCKWISE")) {

src/emc/ini/initraj.cc

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -280,7 +280,7 @@ static int loadTraj(EmcIniFile *trajInifile)
280280
continue; // position t at index of next non-zero mark
281281
}
282282
// there is a mark, so read the string for a value
283-
if (1 == sscanf(&homes[len], "%s", home) &&
283+
if (1 == sscanf(&homes[len], "%254s", home) &&
284284
1 == sscanf(home, "%lf", &d)) {
285285
// got an entry, index into coordinateMark[] is 't'
286286
if (t == 0)
@@ -295,12 +295,15 @@ static int loadTraj(EmcIniFile *trajInifile)
295295
homePose.b = d;
296296
else if (t == 5)
297297
homePose.c = d;
298+
/*
299+
* The following have no effect. The loop only counts [0..5].
298300
else if (t == 6)
299301
homePose.u = d;
300302
else if (t == 7)
301303
homePose.v = d;
302304
else
303305
homePose.w = d;
306+
*/
304307

305308
// position string ptr past this value
306309
len += strlen(home);

src/emc/motion/motion.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -212,9 +212,13 @@ static rtapi_msg_handler_t old_handler = NULL;
212212
static void emc_message_handler(msg_level_t level, const char *fmt, va_list ap)
213213
{
214214
va_list apc;
215+
// False positive. Cppcheck does not seem to know the properties of va_copy()
216+
// cppcheck-suppress va_list_usedBeforeStarted
215217
va_copy(apc, ap);
218+
// cppcheck-suppress va_list_usedBeforeStarted
216219
if(level == RTAPI_MSG_ERR) emcmotErrorPutfv(emcmotError, fmt, apc);
217220
if(old_handler) old_handler(level, fmt, ap);
221+
// cppcheck-suppress va_list_usedBeforeStarted
218222
va_end(apc);
219223
}
220224

src/emc/task/emccanon.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2039,7 +2039,7 @@ void NURBS_FEED_DIVIDE(int lineno,
20392039
// ridefinisco Control_point per il primo SGMENTO (1) NURBS
20402040
// ich definiere Control_point für die ersten SGMENTO (1) NURBS neu
20412041
nurbs_control_points.clear();
2042-
NURBS_G6_CONTROL_POINT CPU;
2042+
NURBS_G6_CONTROL_POINT CPU = {};
20432043
if (j_segment == 0) {
20442044
for (unsigned j = 0;
20452045
j < nurbs_control_points1.size(); ++j) {

src/emc/task/signalhandler.cc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,8 @@ int main(int argc, const char *argv[]) {
138138
sleep(10); // during which a SIGUSR2 will generate a backtrace
139139

140140
void *foo = 0;
141+
// Fully intentional
142+
// cppcheck-suppress nullPointer
141143
memset(foo,0,47); // this segfault would warp us into the gdb window
142144

143145
return 0;

src/emc/usr_intf/sockets.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -259,7 +259,7 @@ char* sockGetError(void)
259259
#else
260260
static char retString[256];
261261
long err;
262-
char* tmp;
262+
char* tmp = NULL;
263263

264264
err = WSAGetLastError();
265265

@@ -276,9 +276,12 @@ char* sockGetError(void)
276276

277277
/* append the message text after the error code and ensure a terminating
278278
character ends the string */
279+
// The 'tmp' buffer is allocated by FormatMessage().
280+
// cppcheck-suppress nullPointer
279281
strncpy(retString + strlen(retString), tmp,
280282
sizeof(retString) - strlen(retString) - 1);
281283
retString[sizeof(retString) - 1] = '\0';
284+
LocalFree(tmp);
282285

283286
return retString;
284287
#endif

src/hal/classicladder/arrays.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -315,7 +315,7 @@ int ClassicLadder_AllocAll()
315315
#endif
316316
VarWordArray = (int *) pByte;
317317
pByte += SIZE_VAR_WORD_ARRAY * sizeof(int);
318-
VarFloatArray =(double *) pByte;
318+
VarFloatArray =(double *)(void *)pByte;
319319
pByte += SIZE_VAR_FLOAT_ARRAY * sizeof(double);
320320
// Allocate last for alignment reasons.
321321
VarArray = (TYPE_FOR_BOOL_VAR *) pByte;

src/hal/classicladder/edit.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1367,7 +1367,7 @@ void EditElementInRung(double x,double y)
13671367
if (EditDatas.NumElementSelectedInToolBar==EDIT_LONG_CONNECTION)
13681368
{
13691369
int ScanX = RungX;
1370-
while(EditDatas.Rung.Element[ScanX][RungY].Type==ELE_FREE && ScanX<RUNG_WIDTH-1 )
1370+
while(ScanX<RUNG_WIDTH-1 && EditDatas.Rung.Element[ScanX][RungY].Type==ELE_FREE)
13711371
{
13721372
EditDatas.Rung.Element[ScanX++][RungY].Type = ELE_CONNECTION;
13731373
}

src/hal/classicladder/edit_gtk.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -390,7 +390,7 @@ void InitAllForToolbar( void )
390390

391391
void CreateOneToolbar( GtkWidget * Box, int NumTable, char * PtrOnToolTipsText[][NBR_ELE_TOOLBAR_X_MAX] )
392392
{
393-
StrElement ToolBarEle;
393+
StrElement ToolBarEle = {};
394394
int ScanToolBarX,ScanToolBarY;
395395
GSList * PtrListRadiosBtn = NULL;
396396
StrToolbarDatas * pToolbarDatas = &ToolbarDatas[ NumTable ];

src/hal/components/stepgen.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -312,11 +312,11 @@
312312
MODULE_AUTHOR("John Kasunich");
313313
MODULE_DESCRIPTION("Step Pulse Generator for EMC HAL");
314314
MODULE_LICENSE("GPL");
315-
int step_type[] = { [0 ... MAX_CHAN-1] = -1 } ;
315+
int step_type[MAX_CHAN] = { [0 ... MAX_CHAN-1] = -1 } ;
316316
RTAPI_MP_ARRAY_INT(step_type,MAX_CHAN,"stepping types for up to 16 channels");
317317
char *ctrl_type[MAX_CHAN];
318318
RTAPI_MP_ARRAY_STRING(ctrl_type,MAX_CHAN,"control type (pos or vel) for up to 16 channels");
319-
int user_step_type[] = { [0 ... MAX_CYCLE-1] = -1 };
319+
int user_step_type[MAX_CYCLE] = { [0 ... MAX_CYCLE-1] = -1 };
320320
RTAPI_MP_ARRAY_INT(user_step_type, MAX_CYCLE,
321321
"lookup table for user-defined step type");
322322

0 commit comments

Comments
 (0)