Skip to content

Fixing BasicIntTypes to allow C Standard Integers and 'bool' #18980

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Mar 14, 2025

Conversation

LeStarch
Copy link
Contributor

The purpose of this check is to ensure that all integral types used by the code point to some fixed size type (e.g. an unsigned 8-bit integer). However, the previous implementation only allowed JPL style typedefs (i.e. U8) and ignored C standard integer types (i.e. uint8_t). This causes the query to false-positive when a typedef resolves to a C standard int type instead of the JPL type even though the spirit of the check has been met.

'bool' has also be allowed as part of the exclusions list as it represents distinct values 'true' and 'false' in C++ code.

Since this significantly reduces the false-positives on my project, I've labeled it "majorAnalysis" per: https://github.com/github/codeql/blob/main/docs/change-notes.md#query-pack-change-categories

The purpose of this check is to ensure that all integral types used by the code point to some fixed size type (e.g. an unsigned 8-bit integer). However; the previous implementation only allowed JPL style typedefs (i.e. U8) and ignored C standard integer types (i.e. uint8_t). This causes the query to false-positive when a typedef resolves to a C standard int type.

'bool' has also be allowed as part of the exclusions list as it represents distinct values 'true' and 'false' in C++ code.
@LeStarch LeStarch requested a review from a team as a code owner March 11, 2025 23:47
Copy link
Contributor

@jketema jketema left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for your contribution.

Reduced the category to minorAnalysis.  Handled bools via a instanceof with BoolType.  Formatted the query correctly.
@LeStarch
Copy link
Contributor Author

@jketema thanks for the expedient review. I believe I have addressed the issues.

@jketema
Copy link
Contributor

jketema commented Mar 13, 2025

Thanks for the updates. Looks like cpp/ql/test/query-tests/JPL_C/LOC-3/Rule 17/BasicIntTypes.expected needs to be updated still. From the test that's failing:

--- expected
+++ actual
@@ -1,3 +1,1 @@
 | test.c:6:26:6:26 | x | x uses the basic integral type unsigned char rather than a typedef with size and signedness. |
-| test.c:7:20:7:20 | x | x uses the basic integral type unsigned char rather than a typedef with size and signedness. |
-| test.c:10:16:10:20 | test7 | test7 uses the basic integral type unsigned char rather than a typedef with size and signedness. |

So just remove the last two lines from the file.

@LeStarch
Copy link
Contributor Author

Should be fixed now!

Copy link
Contributor

@jketema jketema left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Thanks again for your contribution!

@jketema jketema merged commit de2fb03 into github:main Mar 14, 2025
22 checks passed
@LeStarch
Copy link
Contributor Author

@jketema thanks for helping me through the process! This was a very positive open source experience.

@LeStarch LeStarch deleted the jpl-c-basic-integral-types-fix branch April 1, 2025 23:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants