Skip to content

Commit da99d36

Browse files
committed
C++: Turns out we can simplify.
1 parent 7f6fd34 commit da99d36

File tree

4 files changed

+31
-43
lines changed

4 files changed

+31
-43
lines changed
Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,9 @@
1-
| include_twice.h:8:19:8:19 | s | This format specifier for type 'size_t' does not match the argument type '..(*)(..)'. |
2-
| include_twice.h:9:19:9:19 | s | This format specifier for type 'size_t' does not match the argument type '..(*)(..)'. |
3-
| include_twice.h:10:18:10:18 | s | This format specifier for type 'int' does not match the argument type '..(*)(..)'. |
4-
| include_twice.h:10:18:10:18 | s | This format specifier for type 'int' does not match the argument type 'unsigned long'. |
5-
| include_twice.h:11:19:11:19 | s | This format specifier for type 'long' does not match the argument type '..(*)(..)'. |
6-
| include_twice.h:12:20:12:20 | s | This format specifier for type 'long long' does not match the argument type '..(*)(..)'. |
7-
| include_twice.h:13:18:13:18 | s | This format specifier for type 'unsigned int' does not match the argument type '..(*)(..)'. |
8-
| include_twice.h:13:18:13:18 | s | This format specifier for type 'unsigned int' does not match the argument type 'unsigned long'. |
9-
| include_twice.h:21:18:21:39 | ... - ... | This format specifier for type 'int' does not match the argument type 'long'. |
10-
| include_twice.h:21:18:21:39 | ... - ... | This format specifier for type 'int' does not match the argument type 'long'. |
11-
| include_twice.h:24:18:24:39 | ... - ... | This format specifier for type 'unsigned int' does not match the argument type 'long'. |
12-
| include_twice.h:24:18:24:39 | ... - ... | This format specifier for type 'unsigned int' does not match the argument type 'long'. |
1+
| second.cpp:13:19:13:19 | s | This format specifier for type 'size_t' does not match the argument type '..(*)(..)'. |
2+
| second.cpp:14:19:14:19 | s | This format specifier for type 'size_t' does not match the argument type '..(*)(..)'. |
3+
| second.cpp:15:18:15:18 | s | This format specifier for type 'int' does not match the argument type '..(*)(..)'. |
4+
| second.cpp:16:19:16:19 | s | This format specifier for type 'long' does not match the argument type '..(*)(..)'. |
5+
| second.cpp:17:20:17:20 | s | This format specifier for type 'long long' does not match the argument type '..(*)(..)'. |
6+
| second.cpp:18:18:18:18 | s | This format specifier for type 'unsigned int' does not match the argument type '..(*)(..)'. |
7+
| second.cpp:26:18:26:39 | ... - ... | This format specifier for type 'int' does not match the argument type 'long'. |
8+
| second.cpp:29:18:29:39 | ... - ... | This format specifier for type 'unsigned int' does not match the argument type 'long'. |
139
| tests.c:7:18:7:18 | 1 | This format specifier for type 'char *' does not match the argument type 'int'. |
Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,3 @@
1-
// semmle-extractor-options: --expect_errors
2-
3-
int printf(const char * format, ...);
41

52
// defines type size_t plausibly
63
typedef unsigned long size_t;
7-
8-
#include "include_twice.h"

cpp/ql/test/query-tests/Likely Bugs/Format/WrongTypeFormatArguments/Buildless/include_twice.h

Lines changed: 0 additions & 25 deletions
This file was deleted.

cpp/ql/test/query-tests/Likely Bugs/Format/WrongTypeFormatArguments/Buildless/second.cpp

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,26 @@ int printf(const char * format, ...);
55
// defines type `myFunctionPointerType`, referencing `size_t`
66
typedef size_t (*myFunctionPointerType) ();
77

8-
#include "include_twice.h"
8+
void test_size_t() {
9+
size_t s = 0;
10+
11+
printf("%zd", s); // GOOD
12+
printf("%zi", s); // GOOD
13+
printf("%zu", s); // GOOD [FALSE POSITIVE]
14+
printf("%zx", s); // GOOD [FALSE POSITIVE]
15+
printf("%d", s); // BAD
16+
printf("%ld", s); // BAD
17+
printf("%lld", s); // BAD
18+
printf("%u", s); // BAD
19+
20+
char buffer[1024];
21+
22+
printf("%zd", &buffer[1023] - buffer); // GOOD
23+
printf("%zi", &buffer[1023] - buffer); // GOOD
24+
printf("%zu", &buffer[1023] - buffer); // GOOD
25+
printf("%zx", &buffer[1023] - buffer); // GOOD
26+
printf("%d", &buffer[1023] - buffer); // BAD
27+
printf("%ld", &buffer[1023] - buffer); // BAD [NOT DETECTED]
28+
printf("%lld", &buffer[1023] - buffer); // BAD [NOT DETECTED]
29+
printf("%u", &buffer[1023] - buffer); // BAD
30+
}

0 commit comments

Comments
 (0)