Skip to content

Improvements to C code that can improvement robustness #455

Closed
@nhasabni

Description

@nhasabni

Hi,

I work at Intel, and we have developed a tool that detects anomalous programming language expressions that can possibly lead to bugs. We scanned the code repository for this project as it has considerably high number of stars!

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) libs/basekit/source/UArray.c:999

The expression if (UArray_greaterThan_(self, other) | UArray_equals_(self, other)) looks confusing because the intended logic of logical OR seems to be implemented using bitwise OR on integers. While this is technically correct, it is a bit confusing for someone reading this code for the first time. It looks like the better approach would be: 1) one option would be to use bool type from C99, and 2) another option would be to use enum type for true and false.

Case 2) extras/win32vc2005/freeglut-2.2.0/src/freeglut_structure.c#L624 and L626

It looks like expressions if( ln = (SFG_Node *)node->Next ) and if( ln = (SFG_Node *)node->Prev ) in line 624 and 626 resp., are missing parenthesis around the assignment. The expressions, similar to if( (node->Next = next) ), in other parts of the code correctly add those parenthesis.

Any thoughts on the findings? If this looks acceptable, I'm happy to send a pull request with the changes.

Thanks.

Metadata

Metadata

Assignees

No one assigned

    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