Skip to content

Commit bccfbd9

Browse files
authored
Merge pull request #3354 from BsAtHome/fix_cppcheck-various
Fix various cppcheck indicated errors and warnings
2 parents 9732ebd + 2d25f58 commit bccfbd9

File tree

29 files changed

+135
-111
lines changed

29 files changed

+135
-111
lines changed

src/emc/motion/homing.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,8 @@ void homeMotFunctions(void(*pSetRotaryUnlock)(int,int)
3737
,int (*pGetRotaryIsUnlocked)(int)
3838
)
3939
{
40-
SetRotaryUnlock = *pSetRotaryUnlock;
41-
GetRotaryIsUnlocked = *pGetRotaryIsUnlocked;
40+
SetRotaryUnlock = pSetRotaryUnlock;
41+
GetRotaryIsUnlocked = pGetRotaryIsUnlocked;
4242
}
4343

4444
//========================================================

src/emc/motion/stashf_wrap.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,10 @@ const char *fmt, *efmt;
9191
if(*fmt) {
9292
result = PRINT("%s", fmt);
9393
if(result < 0) return SET_ERRNO(result);
94-
EXTRA
94+
// The below expansion of 'EXTRA' makes no sense. The function is about
95+
// to exit and changing anything here does not change the outcome in
96+
// any way. Therefore, make it a comment.
97+
// EXTRA
9598
}
9699

97100
return SET_ERRNO(result);

src/emc/pythonplugin/python_plugin.hh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,8 +70,8 @@ public:
7070
int plugin_status() { return status; };
7171
bool usable() { return (status >= PLUGIN_OK); }
7272
int initialize();
73-
std::string last_exception() { return exception_msg; };
74-
std::string last_errmsg() { return error_msg; };
73+
const std::string& last_exception() { return exception_msg; };
74+
const std::string& last_errmsg() { return error_msg; };
7575
boost::python::object main_namespace;
7676

7777
private:

src/emc/rs274ngc/interp_python.cc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -293,6 +293,8 @@ pycontext::~pycontext() { delete impl; }
293293
pycontext::pycontext(const pycontext &other)
294294
: impl(new pycontext_impl(*other.impl)) {}
295295
pycontext &pycontext::operator=(const pycontext &other) {
296+
if(&other == this) // Assign to self
297+
return *this;
296298
delete impl;
297299
impl = new pycontext_impl(*other.impl);
298300
return *this;

src/emc/rs274ngc/rs274ngc_pre.cc

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1953,6 +1953,13 @@ int Interp::save_parameters(const char *filename, //!< name of file to writ
19531953
infile = fopen(filename, "r");
19541954
if(!infile)
19551955
infile = fopen("/dev/null", "r");
1956+
if(!infile) {
1957+
// If we can't open the 'filename', we may not be able to open "/dev/null"
1958+
// either. If so, print an error, close 'outfile' and continue.
1959+
perror("Interp::save_parameters(): fopen(/dev/null)");
1960+
fclose(outfile);
1961+
return INTERP_OK;
1962+
}
19561963

19571964
k = 0;
19581965
index = 0;

src/emc/sai/saicanon.cc

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -315,8 +315,8 @@ void STOP_SPEED_FEED_SYNCH()
315315
void NURBS_G5_FEED(int /*lineno*/, const std::vector<NURBS_CONTROL_POINT>& nurbs_control_points, unsigned int /*nurbs_order*/, CANON_PLANE /*plane*/) {
316316
ECHO_WITH_ARGS("%lu, ...", (unsigned long)nurbs_control_points.size());
317317

318-
_sai._program_position_x = nurbs_control_points[nurbs_control_points.size()].NURBS_X;
319-
_sai._program_position_y = nurbs_control_points[nurbs_control_points.size()].NURBS_Y;
318+
_sai._program_position_x = nurbs_control_points[nurbs_control_points.size()-1].NURBS_X;
319+
_sai._program_position_y = nurbs_control_points[nurbs_control_points.size()-1].NURBS_Y;
320320
}
321321

322322
/* Machining Functions G_6_2 */
@@ -325,8 +325,8 @@ void NURBS_G6_FEED(int /*lineno*/, const std::vector<NURBS_G6_CONTROL_POINT>& nu
325325
print_nc_line_number();
326326
fprintf(_outfile, "saicanon NURBS_G6_FEED_(%lu, ...)\n", (unsigned long)nurbs_control_points.size());
327327

328-
_sai._program_position_x = nurbs_control_points[nurbs_control_points.size()].NURBS_X;
329-
_sai._program_position_y = nurbs_control_points[nurbs_control_points.size()].NURBS_Y;
328+
_sai._program_position_x = nurbs_control_points[nurbs_control_points.size()-1].NURBS_X;
329+
_sai._program_position_y = nurbs_control_points[nurbs_control_points.size()-1].NURBS_Y;
330330
}
331331

332332
void ARC_FEED(int /*line_number*/,

src/emc/task/taskclass.hh

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,10 @@ public:
5454
Task(EMC_IO_STAT &emcioStatus_in);
5555
virtual ~Task();
5656

57+
// Don't copy or assign
58+
Task(const Task&) = delete;
59+
Task& operator=(const Task&) = delete;
60+
5761
virtual int emcIoInit();
5862
virtual int emcIoAbort(EMC_ABORT reason);
5963
virtual int emcAuxEstopOn();

src/emc/tp/tp.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -82,12 +82,12 @@ void tpMotFunctions(void( *pDioWrite)(int,char)
8282
,double(*paxis_get_acc_limit)(int)
8383
)
8484
{
85-
_DioWrite = *pDioWrite;
86-
_AioWrite = *pAioWrite;
87-
_SetRotaryUnlock = *pSetRotaryUnlock;
88-
_GetRotaryIsUnlocked = *pGetRotaryIsUnlocked;
89-
_axis_get_vel_limit = *paxis_get_vel_limit;
90-
_axis_get_acc_limit = *paxis_get_acc_limit;
85+
_DioWrite = pDioWrite;
86+
_AioWrite = pAioWrite;
87+
_SetRotaryUnlock = pSetRotaryUnlock;
88+
_GetRotaryIsUnlocked = pGetRotaryIsUnlocked;
89+
_axis_get_vel_limit = paxis_get_vel_limit;
90+
_axis_get_acc_limit = paxis_get_acc_limit;
9191
}
9292

9393
void tpMotData(emcmot_status_t *pstatus

src/emc/usr_intf/emcrsh.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1839,7 +1839,7 @@ static cmdResponseType getBrake(connectionRecType *context)
18391839
if (n != spindle && spindle != -1)
18401840
continue;
18411841

1842-
if (emcStatus->motion.spindle[spindle].brake == 1)
1842+
if (emcStatus->motion.spindle[n].brake == 1)
18431843
OUT(pBrakeStr, "ON");
18441844
else
18451845
OUT(pBrakeStr, "OFF");

src/emc/usr_intf/emcsched.cc

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -74,9 +74,9 @@ class SchedEntry {
7474
void setOffsets(float x, float y, float z);
7575
int getZone() const;
7676
void setZone(int z);
77-
string getFileName() const;
77+
const string& getFileName() const;
7878
void setFileName(const string& s);
79-
string getProgramName() const;
79+
const string& getProgramName() const;
8080
void setProgramName(const string& s);
8181
float getFeedOverride() const;
8282
void setFeedOverride(float f);
@@ -146,15 +146,15 @@ void SchedEntry::setZone(int z) {
146146
zone = z;
147147
}
148148

149-
string SchedEntry::getFileName() const {
149+
const string& SchedEntry::getFileName() const {
150150
return fileName;
151151
}
152152

153153
void SchedEntry::setFileName(const string& s) {
154154
fileName = s;
155155
}
156156

157-
string SchedEntry::getProgramName() const {
157+
const string& SchedEntry::getProgramName() const {
158158
return programName;
159159
}
160160

@@ -369,7 +369,7 @@ int getProgramById(int id, qRecType *qRec) {
369369
for (i=q.begin(); i!=q.end(); ++i) {
370370
if (i->getTagId() == id) break;
371371
}
372-
if (i->getTagId() != id) return -1;
372+
if (i == q.end() || i->getTagId() != id) return -1;
373373
qRec->priority = i->getPriority();
374374
qRec->tagId = i->getTagId();
375375
i->getOffsets(qRec->xpos, qRec->ypos, qRec->zpos);
@@ -384,14 +384,11 @@ int getProgramById(int id, qRecType *qRec) {
384384

385385
int getProgramByIndex(int idx, qRecType *qRec) {
386386
list<SchedEntry>::iterator i;
387-
int index;
388387

389-
if ((unsigned int) idx >= q.size()) return -1;
390-
index = 0;
391-
for (i=q.begin(); i!=q.end(); ++i) {
392-
if (index == idx) break;
393-
index++;
394-
}
388+
for(i = q.begin(); idx > 0; ++i) {
389+
if(i == q.end()) return -1; // return if idx was larger than number of entries
390+
--idx;
391+
}
395392
qRec->priority = i->getPriority();
396393
qRec->tagId = i->getTagId();
397394
i->getOffsets(qRec->xpos, qRec->ypos, qRec->zpos);

0 commit comments

Comments
 (0)