File tree Expand file tree Collapse file tree 4 files changed +47
-0
lines changed
cpp/ql/test/query-tests/Likely Bugs/Format/WrongTypeFormatArguments/Buildless Expand file tree Collapse file tree 4 files changed +47
-0
lines changed Original file line number Diff line number Diff line change 1+ | include_twice.h:10:18:10:18 | s | This format specifier for type 'int' does not match the argument type 'unsigned long'. |
2+ | include_twice.h:13:18:13:18 | s | This format specifier for type 'unsigned int' does not match the argument type 'unsigned long'. |
3+ | include_twice.h:21:18:21:39 | ... - ... | This format specifier for type 'int' does not match the argument type 'long'. |
4+ | include_twice.h:21:18:21:39 | ... - ... | This format specifier for type 'int' does not match the argument type 'long'. |
5+ | include_twice.h:24:18:24:39 | ... - ... | This format specifier for type 'unsigned int' does not match the argument type 'long'. |
6+ | include_twice.h:24:18:24:39 | ... - ... | This format specifier for type 'unsigned int' does not match the argument type 'long'. |
17| tests.c:7:18:7: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 1+ // semmle-extractor-options: --expect_errors
2+
3+ int printf (const char * format, ...);
4+
5+ // defines type size_t plausibly
6+ typedef unsigned long size_t ;
7+
8+ #include " include_twice.h"
Original file line number Diff line number Diff line change 1+ // semmle-extractor-options: --expect_errors
2+
3+ void test_size_t () {
4+ size_t s = 0 ;
5+
6+ printf ("%zd" , s ); // GOOD
7+ printf ("%zi" , s ); // GOOD
8+ printf ("%zu" , s ); // GOOD
9+ printf ("%zx" , s ); // GOOD
10+ printf ("%d" , s ); // BAD
11+ printf ("%ld" , s ); // BAD [NOT DETECTED]
12+ printf ("%lld" , s ); // BAD [NOT DETECTED]
13+ printf ("%u" , s ); // BAD
14+
15+ char buffer [1024 ];
16+
17+ printf ("%zd" , & buffer [1023 ] - buffer ); // GOOD
18+ printf ("%zi" , & buffer [1023 ] - buffer ); // GOOD
19+ printf ("%zu" , & buffer [1023 ] - buffer ); // GOOD
20+ printf ("%zx" , & buffer [1023 ] - buffer ); // GOOD
21+ printf ("%d" , & buffer [1023 ] - buffer ); // BAD
22+ printf ("%ld" , & buffer [1023 ] - buffer ); // BAD [NOT DETECTED]
23+ printf ("%lld" , & buffer [1023 ] - buffer ); // BAD [NOT DETECTED]
24+ printf ("%u" , & buffer [1023 ] - buffer ); // BAD
25+ }
Original file line number Diff line number Diff line change 1+ // semmle-extractor-options: --expect_errors
2+
3+ int printf (const char * format, ...);
4+
5+ // defines type `myFunctionPointerType`
6+ typedef int (*myFunctionPointerType) ();
7+
8+ #include " include_twice.h"
You can’t perform that action at this time.
0 commit comments