Skip to content

Commit 231e3c2

Browse files
committed
C++: Tests for cpp/wrong-type-format-argument
1 parent 5bfd22e commit 231e3c2

File tree

2 files changed

+18
-3
lines changed

2 files changed

+18
-3
lines changed
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,13 @@
11
| tests.c:7:18:7:18 | 1 | This format specifier for type 'char *' does not match the argument type 'int'. |
2+
| tests.c:12:27:12:29 | 42 | This format specifier for type 'int' does not match the argument type 'long'. |
3+
| tests.c:12:32:12:35 | 42 | This format specifier for type 'int' does not match the argument type 'unsigned long'. |
4+
| tests.c:12:38:12:40 | 42 | This format specifier for type 'unsigned int' does not match the argument type 'long'. |
5+
| tests.c:12:43:12:46 | 42 | This format specifier for type 'unsigned int' does not match the argument type 'unsigned long'. |
6+
| tests.c:13:27:13:30 | 42 | This format specifier for type 'int' does not match the argument type 'long long'. |
7+
| tests.c:13:33:13:37 | 42 | This format specifier for type 'int' does not match the argument type 'unsigned long long'. |
8+
| tests.c:13:40:13:43 | 42 | This format specifier for type 'unsigned int' does not match the argument type 'long long'. |
9+
| tests.c:13:46:13:50 | 42 | This format specifier for type 'unsigned int' does not match the argument type 'unsigned long long'. |
10+
| tests.c:14:31:14:32 | 42 | This format specifier for type 'long' does not match the argument type 'int'. |
11+
| tests.c:14:35:14:37 | 42 | This format specifier for type 'long' does not match the argument type 'unsigned int'. |
12+
| tests.c:14:40:14:41 | 42 | This format specifier for type 'unsigned long' does not match the argument type 'int'. |
13+
| tests.c:14:44:14:46 | 42 | This format specifier for type 'unsigned long' does not match the argument type 'unsigned int'. |
Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,15 @@
1-
// semmle-extractor-options: --expect_errors
1+
// semmle-extractor-options: --expect_errors --build-mode none
22

33
int printf(const char * format, ...);
44
int fprintf();
55

66
void f(UNKNOWN_CHAR * str) {
77
printf("%s", 1); // BAD
8-
printf("%s", implicit_function()); // GOOD - we should ignore the type
8+
printf("%s", implicit_function()); // GOOD: we should ignore the type
99
sprintf(0, "%s", ""); // GOOD
1010
fprintf(0, "%s", ""); // GOOD
11-
printf("%s", str); // GOOD - erroneous type is ignored
11+
printf("%s", str); // GOOD: erroneous type is ignored
12+
printf("%d %d %u %u", 42l, 42ul, 42l, 42ul); // BAD (FP)
13+
printf("%d %d %u %u", 42ll, 42ull, 42ll, 42ull); // BAD
14+
printf("%ld %ld %lu %lu", 42, 42u, 42, 42u); // BAD
1215
}

0 commit comments

Comments
 (0)