Skip to content
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

C++: Improvements to reduce false alarms #16149

Merged
merged 10 commits into from
Apr 16, 2024
Merged

Conversation

codeqlhelper
Copy link
Contributor

No description provided.

@codeqlhelper codeqlhelper requested a review from a team as a code owner April 8, 2024 16:11
@github-actions github-actions bot added the C++ label Apr 8, 2024
@MathiasVP MathiasVP self-requested a review April 9, 2024 14:07
Copy link
Contributor

@MathiasVP MathiasVP left a comment

Choose a reason for hiding this comment

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

Hi @codeqlhelper,

Thanks for your contribution! I've added some suggestions that I think will improve this PR, but otherwise I think this looks good.

Ideally, this PR should also come with some added tests, but it doesn't look like these queries have any tests in our repository 😬 If you have some tests lying around for when you were doing these changes please post them as comments in here and I'll be happy to incorporate them into actual query tests once I've set up the right folder structure for it (that probably won't be done as part of this PR, though).

cpp/ql/src/Critical/GlobalUseBeforeInit.ql Outdated Show resolved Hide resolved
cpp/ql/src/Critical/GlobalUseBeforeInit.ql Outdated Show resolved Hide resolved
cpp/ql/src/change-notes/2024-04-09-reduce-FP.md Outdated Show resolved Hide resolved
cpp/ql/src/Critical/GlobalUseBeforeInit.ql Outdated Show resolved Hide resolved
@MathiasVP
Copy link
Contributor

MathiasVP commented Apr 9, 2024

CI is telling me that you need to format GlobalUseBeforeInit.ql to match our style guidelines. If you're using our VSCode extension you can hit shift + cmd + p (or shift + ctrl + p on non-Mac, I guess?) and select Format Document to automatically format the query to match our styleguide.

Edit: I figured I might as well push the autoformat myself to spare you those annoying details 🙂

@MathiasVP MathiasVP changed the title Improvements to reduce false alarms C++: Improvements to reduce false alarms Apr 10, 2024
@codeqlhelper
Copy link
Contributor Author

Testcase for GlobalUseBeforeInit.ql

#include <stdarg.h>
#include <stdio.h>

int a = 1;

int my_printf(const char * fmt, ...)
{
    va_list vl;
    int ret;
    va_start(vl, fmt);
    ret = vfprintf(stdout, fmt, vl);
    ret = vfprintf(stderr, fmt, vl);
    va_end(vl);
    return ret;
}

int f1()
{
    my_printf("%d\n", a + 2);
    return 0;
}

int main()
{
    int b = f1();
    return 0;
}

Testcase for InconsistentNullnessTesting.ql is somewhat complicated. I failed to provide a simple manual sample.
On my ubuntu-22.04, configure it with

./configure --without-xml CC=gcc CFLAGS="-O0 -g" CXXFLAGS="-O0 -g"
# Then build the DB with `make`
# Then query the DB with `InconsistentNullnessTesting.ql`
codeql query run $ql_path -d $db_path -o $bqrs_name
codeql bqrs decode --format=csv --entities=all --output="$csv_name" $bqrs_name

Then you can see many warnings like coders/art.c:111, which is not expected.
GraphicsMagick-1.3.26.tar.gz

In terms of minor or major, both of them are OK for me. I select majorAnalysis since the document marks reducing FP in majorAnalysis, and the outcome may influence some users.
https://github.com/github/codeql/blob/996f535f0b5f1eedc45d6839be8f7bef93e1f6a2/docs/change-notes.md?plain=1#L57C1-L57C193

@MathiasVP
Copy link
Contributor

Thanks for the detailed instructions. I've added your tests to the PR now. Since the tests needed to be placed in a particular directory that matches our existing directory structure in a way that's not written down anywhere (I think) I simply pushed the required changes to your PR. This all LGTM me now and I'll approve it once CI is green 🤞

@MathiasVP MathiasVP merged commit 8888ee9 into github:main Apr 16, 2024
15 checks passed
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