Skip to content

Improvements to C code for robustness #263

@nhasabni

Description

@nhasabni

Hi,

I work at Intel, and we have developed a tool, named ControlFlag, that detects anomalous programming language expressions that can possibly lead to bugs. We scanned the code repository for this project, and we found a couple of places where the code/expressions are confusing and seem to implement the logic in a rather convoluted manner. We think that the expressions could be rewritten to capture the logic accurately and precisely.

Case 1) Expression (l_inbuf[2] | 1) in the following code seems confusing because it would always evaluate to true as per C language. Was the intention to say (l_inbuf[2] & 1)? This is in line 108 below

vrpn/vrpn_5DT16.C

Lines 108 to 113 in c8465be

if (l_inbuf[2] | 1) //right or left glove
{
VRPN_MSG_WARNING ("A right glove is ready");
} else {
VRPN_MSG_WARNING ("A left glove is ready");
}

Case 2) Similarly, expression if (l_inbuf[3] | 1) seems confusing. Was the intention to say if (l_inbuf[3] & 1)? This is in line 114 below

vrpn/vrpn_5DT16.C

Lines 114 to 119 in c8465be

if (l_inbuf[3] | 1) //wireless glove or wired
{
VRPN_MSG_WARNING ("no wireless glove");
} else {
VRPN_MSG_WARNING ("wireless glove");
}

Case 3) Similarly, expression if (l_inbuf[4] | 1) seems confusing for the same reason. This is in line 194 below

vrpn/vrpn_Analog_5dt.C

Lines 194 to 198 in c8465be

if (l_inbuf[4] | 1) {
VRPN_MSG_INFO ("A right glove is ready");
} else {
VRPN_MSG_INFO ("A left glove is ready");
}

Case 4) For the same reason, expression if (l_inbuf[5] | 16) in line 199 look confusing.

vrpn/vrpn_Analog_5dt.C

Lines 199 to 203 in c8465be

if (l_inbuf[5] | 16) {
VRPN_MSG_INFO ("Pitch and Roll are available");
} else {
VRPN_MSG_INFO ("Pitch and Roll are not available");
}

I would be happy to fix these issues, if someone can confirm them as bugs.

Metadata

Metadata

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions