File tree Expand file tree Collapse file tree 4 files changed +39
-1
lines changed
test/query-tests/Likely Bugs/Format/WrongTypeFormatArguments/Buildless Expand file tree Collapse file tree 4 files changed +39
-1
lines changed Original file line number Diff line number Diff line change @@ -171,7 +171,9 @@ where
171
171
not arg .isAffectedByMacro ( ) and
172
172
not arg .isFromUninstantiatedTemplate ( _) and
173
173
not actual .stripType ( ) instanceof ErroneousType and
174
- not arg .( Call ) .mayBeFromImplicitlyDeclaredFunction ( )
174
+ not arg .( Call ) .mayBeFromImplicitlyDeclaredFunction ( ) and
175
+ // Make sure that the format function definition is consistent
176
+ count ( ffc .getTarget ( ) .getFormatParameterIndex ( ) ) = 1
175
177
select arg ,
176
178
"This format specifier for type '" + expected .getName ( ) + "' does not match the argument type '" +
177
179
actual .getUnspecifiedType ( ) .getName ( ) + "'."
Original file line number Diff line number Diff line change
1
+ ---
2
+ category : minorAnalysis
3
+ ---
4
+ * The "Wrong type of arguments to formatting function" query (` cpp/wrong-type-format-argument ` ) now produces fewer FPs if the formatting function has multiple definitions.
Original file line number Diff line number Diff line change @@ -10,3 +10,21 @@ void f(UNKNOWN_CHAR * str) {
10
10
fprintf (0 , "%s" , "" ); // GOOD
11
11
printf ("%s" , str ); // GOOD - erroneous type is ignored
12
12
}
13
+
14
+ #define va_list void*
15
+ #define va_start (x , y ) x = 0;
16
+ #define va_arg (x , y ) ((y)x)
17
+ #define va_end (x )
18
+ int vprintf (const char * format , va_list args );
19
+
20
+ int my_printf (const char * format , ...) {
21
+ va_list args ;
22
+ va_start (args , format );
23
+ int result = vprintf (format , args );
24
+ va_end (args );
25
+ return result ;
26
+ }
27
+
28
+ void linker_awareness_test () {
29
+ my_printf ("%s%d" , "" , 1 ); // GOOD
30
+ }
Original file line number Diff line number Diff line change
1
+ #define va_list void*
2
+ #define va_start (x , y ) x = 0;
3
+ #define va_arg (x , y ) ((y)x)
4
+ #define va_end (x )
5
+
6
+ int vprintf (const char * format , va_list args );
7
+
8
+ int my_printf (void * p ,const char * format , ...) {
9
+ va_list args ;
10
+ va_start (args , format );
11
+ int result = vprintf (format , args );
12
+ va_end (args );
13
+ return result ;
14
+ }
You can’t perform that action at this time.
0 commit comments