Skip to content

Commit 3a0dfbd

Browse files
committed
CPP: Normalize test cases between some of the WrongTypeFormatArguments tests.
1 parent 1203c73 commit 3a0dfbd

File tree

4 files changed

+64
-4
lines changed

4 files changed

+64
-4
lines changed

cpp/ql/test/query-tests/Likely Bugs/Format/WrongTypeFormatArguments/Linux_unsigned_chars/WrongTypeFormatArguments.expected

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,9 @@
1010
| printf1.h:44:18:44:20 | ull | This argument should be of type 'int' but is of type 'unsigned long long' |
1111
| printf1.h:45:18:45:20 | ull | This argument should be of type 'unsigned int' but is of type 'unsigned long long' |
1212
| printf1.h:46:18:46:20 | ull | This argument should be of type 'unsigned int' but is of type 'unsigned long long' |
13-
| printf1.h:126:18:126:19 | wc | This argument should be of type 'char *' but is of type 'wchar_t *' |
14-
| printf1.h:127:18:127:18 | c | This argument should be of type 'wchar_t *' but is of type 'char *' |
13+
| printf1.h:130:18:130:18 | 0 | This argument should be of type 'void *' but is of type 'int' |
14+
| printf1.h:154:18:154:19 | wc | This argument should be of type 'char *' but is of type 'wchar_t *' |
15+
| printf1.h:155:18:155:18 | c | This argument should be of type 'wchar_t *' but is of type 'char *' |
1516
| real_world.h:61:21:61:22 | & ... | This argument should be of type 'int *' but is of type 'short *' |
1617
| real_world.h:62:22:62:23 | & ... | This argument should be of type 'short *' but is of type 'int *' |
1718
| real_world.h:63:22:63:24 | & ... | This argument should be of type 'short *' but is of type 'unsigned int *' |

cpp/ql/test/query-tests/Likely Bugs/Format/WrongTypeFormatArguments/Linux_unsigned_chars/printf1.h

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,34 @@ void fun1(unsigned char* a, unsigned char* b) {
102102
printf("%td\n", a-b); // GOOD
103103
}
104104

105+
typedef wchar_t WCHAR_T; // WCHAR_T -> wchar_t -> int
106+
typedef int MYCHAR; // MYCHAR -> int (notably not via the wchar_t typedef)
107+
108+
void fun2() {
109+
wchar_t *myString1;
110+
WCHAR_T *myString2;
111+
int *myString3;
112+
MYCHAR *myString4;
113+
114+
printf("%S", myString1); // GOOD
115+
printf("%S", myString2); // GOOD
116+
printf("%S", myString3); // GOOD
117+
printf("%S", myString4); // GOOD
118+
}
119+
120+
typedef void *VOIDPTR;
121+
typedef int (*FUNPTR)(int);
122+
123+
void fun3(void *p1, VOIDPTR p2, FUNPTR p3, char *p4)
124+
{
125+
printf("%p\n", p1); // GOOD
126+
printf("%p\n", p2); // GOOD
127+
printf("%p\n", p3); // GOOD
128+
printf("%p\n", p4); // GOOD
129+
printf("%p\n", p4 + 1); // GOOD
130+
printf("%p\n", 0); // GOOD [FALSE POSITIVE]
131+
}
132+
105133
typedef unsigned int wint_t;
106134

107135
void test_chars(char c, wchar_t wc, wint_t wt)

cpp/ql/test/query-tests/Likely Bugs/Format/WrongTypeFormatArguments/Microsoft/WrongTypeFormatArguments.expected

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,11 @@
1616
| printf1.h:74:19:74:22 | C_ST | This argument should be of type 'ssize_t' but is of type 'unsigned long long' |
1717
| printf1.h:75:19:75:28 | sizeof(<expr>) | This argument should be of type 'ssize_t' but is of type 'unsigned long long' |
1818
| printf1.h:84:23:84:35 | ... - ... | This argument should be of type 'ssize_t' but is of type 'long long' |
19-
| printf1.h:125:18:125:18 | c | This argument should be of type '__wchar_t *' but is of type 'char *' |
20-
| printf1.h:128:18:128:19 | wc | This argument should be of type 'char *' but is of type '__wchar_t *' |
19+
| printf1.h:116:16:116:24 | myString3 | This argument should be of type '__wchar_t *' but is of type 'int *' |
20+
| printf1.h:117:16:117:24 | myString4 | This argument should be of type '__wchar_t *' but is of type 'int *' |
21+
| printf1.h:130:18:130:18 | 0 | This argument should be of type 'void *' but is of type 'int' |
22+
| printf1.h:153:18:153:18 | c | This argument should be of type '__wchar_t *' but is of type 'char *' |
23+
| printf1.h:156:18:156:19 | wc | This argument should be of type 'char *' but is of type '__wchar_t *' |
2124
| real_world.h:61:21:61:22 | & ... | This argument should be of type 'int *' but is of type 'short *' |
2225
| real_world.h:62:22:62:23 | & ... | This argument should be of type 'short *' but is of type 'int *' |
2326
| real_world.h:63:22:63:24 | & ... | This argument should be of type 'short *' but is of type 'unsigned int *' |

cpp/ql/test/query-tests/Likely Bugs/Format/WrongTypeFormatArguments/Microsoft/printf1.h

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,34 @@ void fun1(unsigned char* a, unsigned char* b) {
102102
printf("%td\n", a-b); // GOOD
103103
}
104104

105+
typedef wchar_t WCHAR_T; // WCHAR_T -> wchar_t
106+
typedef int MYCHAR; // MYCHAR -> int
107+
108+
void fun2() {
109+
wchar_t *myString1;
110+
WCHAR_T *myString2;
111+
int *myString3;
112+
MYCHAR *myString4;
113+
114+
printf("%S", myString1); // GOOD
115+
printf("%S", myString2); // GOOD
116+
printf("%S", myString3); // BAD
117+
printf("%S", myString4); // BAD
118+
}
119+
120+
typedef void *VOIDPTR;
121+
typedef int (*FUNPTR)(int);
122+
123+
void fun3(void *p1, VOIDPTR p2, FUNPTR p3, char *p4)
124+
{
125+
printf("%p\n", p1); // GOOD
126+
printf("%p\n", p2); // GOOD
127+
printf("%p\n", p3); // GOOD
128+
printf("%p\n", p4); // GOOD
129+
printf("%p\n", p4 + 1); // GOOD
130+
printf("%p\n", 0); // GOOD [FALSE POSITIVE]
131+
}
132+
105133
typedef unsigned int wint_t;
106134

107135
void test_chars(char c, wchar_t wc, wint_t wt)

0 commit comments

Comments
 (0)