Skip to content

Commit d23a3f8

Browse files
committed
C++: Add a test case for WrongTypeFormatArguments involving code that's included twice.
1 parent 6a904ed commit d23a3f8

File tree

4 files changed

+47
-0
lines changed

4 files changed

+47
-0
lines changed
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,7 @@
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'. |
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
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"
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
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+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
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"

0 commit comments

Comments
 (0)