-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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++: Reduce FPs in cpp/wrong-type-format-argument due to extraction errors #17775
Changes from 2 commits
fe85e00
853128c
6a48ad0
d88a674
ceceee1
9758e02
5315a5c
4341fab
4197805
0fcabc4
c5a082f
f37be68
421413a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
--- | ||
category: minorAnalysis | ||
--- | ||
* Fixed false positives in the `cpp/wrong-type-format-argument` ("Wrong type of arguments to formatting function") query if there are extraction errors in the function. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is technically not true, as there are valid cases where a function is implicitly defined and correctly being used as a argument in a printf call. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, it might also reject true-positives. Do you have a suggested text I could use? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think we mostly want to be explicit about what we ignore, i.e., calls to functions that are implicitly declared, as in the majority of cases we see that these are due to extraction errors, and not because the codebase is pre-C99 C-code, which allows implicit function declarations. |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
| tests.c:6:18:6:18 | 1 | This format specifier for type 'char *' does not match the argument type 'int'. | |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Likely Bugs/Format/WrongTypeFormatArguments.ql |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
// semmle-extractor-options: --expect_errors | ||
|
||
int printf(const char * format, ...); | ||
|
||
void f() { | ||
printf("%s", 1); // BAD | ||
printf("%s", implicit_function()); // GOOD - we should ignore the type | ||
sprintf(0, "%s", ""); // GOOD | ||
fprintf(0, "%s", ""); // GOOD | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This one is now good, because There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes. |
||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks odd. It feels like there might be a bug in one of the super classes. Otherwise, why doesn't
Printf
have a similar predicate?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't fully understand this, but it's what's needed to remove false-positives on the
asterisk
project. The declaration ofint fprintf()
in the last commit (5315a5c) replicates what happened in the database. I briefly forgot why I needed that line.This line is safe because class
Fprintf
always has 2 arguments.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The root cause is actually that the extractor sometimes fails to mark function declarations as implicit. Hmm. Maybe that's the fix.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed instead using 4341fab. I couldn't find a nice way to identify these extraction errors but hopefully the solution makes sense.