Skip to content

Commit

Permalink
Merge pull request #3362 from BsAtHome/fix_cppchecks
Browse files Browse the repository at this point in the history
Fix near last cppcheck problems
  • Loading branch information
andypugh authored Mar 3, 2025
2 parents 2eccf7d + bc194e8 commit 4dd98d4
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 1 deletion.
1 change: 1 addition & 0 deletions src/emc/usr_intf/emcsh.cc
Original file line number Diff line number Diff line change
Expand Up @@ -3203,6 +3203,7 @@ static int emc_pendant(ClientData /*clientdata*/,
if (strcmp(port, "/dev/psaux")) { // For Serial mice
inBytes[1] = fgetc(inFile); // read the first Byte
if (inBytes[1] != 77) { // If first byte not "M"
fseek(inFile, 0, SEEK_CUR); // C standard: write-after-read needs this
fputc(77, inFile); // Request data resent
fflush(inFile);
inBytes[1] = fgetc(inFile); // and hope it is
Expand Down
11 changes: 10 additions & 1 deletion src/hal/drivers/mesa-hostmot2/hm2_eth.c
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@ static int *kvlist_lookup(struct rtapi_list_head *head, const char *name) {
if(strncmp(name, ent->key, sizeof(ent->key)) == 0) return &ent->value;
}
struct kvlist *ent = rtapi_kzalloc(sizeof(struct kvlist), RTAPI_GPF_KERNEL);
if(!ent)
return NULL;
strncpy(ent->key, name, sizeof(ent->key)-1);
rtapi_list_add(&ent->list, head);
return &ent->value;
Expand Down Expand Up @@ -1047,6 +1049,8 @@ static int hm2_eth_set_force_enqueue(hm2_lowlevel_io_t *this, int do_enqueue) {

static int llio_idx(const char *llio_name) {
int *idx = kvlist_lookup(&board_num, llio_name);
if(!idx)
return -1;
return (*idx)++;
}

Expand Down Expand Up @@ -1439,7 +1443,10 @@ static int hm2_eth_probe(hm2_eth_t *board) {

LL_PRINT("discovered %.*s\n", 16, board_name);

rtapi_snprintf(board->llio.name, sizeof(board->llio.name), "hm2_%.*s.%d", (int)strlen(llio_name), llio_name, llio_idx(llio_name));
int llidx = llio_idx(llio_name);
if(llidx < 0)
return -ENOMEM;
rtapi_snprintf(board->llio.name, sizeof(board->llio.name), "hm2_%.*s.%d", (int)strlen(llio_name), llio_name, llidx);

board->llio.comp_id = comp_id;

Expand Down Expand Up @@ -1585,6 +1592,8 @@ int rtapi_app_main(void) {
}
boards[i].read_cnt = boards[i].write_cnt = 0;
int *added = kvlist_lookup(&ifnames, ifptr);
if(!added)
goto error;
if(*added) continue;
install_iptables_perinterface(ifptr);
*added = 1;
Expand Down
7 changes: 7 additions & 0 deletions src/hal/drivers/mesa-hostmot2/hm2_spix.c
Original file line number Diff line number Diff line change
Expand Up @@ -572,11 +572,18 @@ static int spix_setup(void)

// Decompose the device-tree buffer into a string-list with the pointers to
// each string in dtcs. Don't go beyond the buffer's size.
// Note on cppcheck: it thinks that cptr can be NULL, but it cannot. It is
// initialized at the start of the buffer and moves inside it. The cptr is
// set to NULL when the double NUL character is detected at the end of the
// buffer. The loop terminates if cptr becomes NULL and cannot cause
// strlen() to be fed a NULL-pointer.
memset(dtcs, 0, sizeof(dtcs));
cptr = buf;
for(unsigned i = 0; i < DTC_MAX && cptr; i++) {
dtcs[i] = cptr;
// cppcheck-suppress nullPointer
int j = strlen(cptr);
// cppcheck-suppress nullPointerArithmetic
if((cptr - buf) + j + 1 < buflen)
cptr += j + 1;
else
Expand Down
3 changes: 3 additions & 0 deletions src/rtapi/uspace_rtapi_app.cc
Original file line number Diff line number Diff line change
Expand Up @@ -523,9 +523,12 @@ int main(int argc, char **argv) {
int fallback_uid = fallback_uid_str ? atoi(fallback_uid_str) : 0;
if(fallback_uid == 0)
{
// Cppcheck cannot see EMC2_BIN_DIR when RTAPI is defined, but that
// doesn't happen in uspace.
fprintf(stderr,
"Refusing to run as root without fallback UID specified\n"
"To run under a debugger with I/O, use e.g.,\n"
// cppcheck-suppress unknownMacro
" sudo env RTAPI_UID=`id -u` RTAPI_FIFO_PATH=$HOME/.rtapi_fifo gdb " EMC2_BIN_DIR "/rtapi_app\n");
exit(1);
}
Expand Down

0 comments on commit 4dd98d4

Please sign in to comment.