Skip to content

Commit 98c3e14

Browse files
committed
CPP: Add test cases of %I64 and similar.
1 parent 3a0dfbd commit 98c3e14

File tree

8 files changed

+144
-0
lines changed

8 files changed

+144
-0
lines changed

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
| printf1.h:46:18:46:20 | ull | This argument should be of type 'unsigned int' but is of type 'unsigned long long' |
1313
| printf1.h:113:17:113:17 | d | This argument should be of type 'long double' but is of type 'double' |
1414
| printf1.h:114:18:114:18 | d | This argument should be of type 'long double' but is of type 'double' |
15+
| printf1.h:147:19:147:19 | i | This argument should be of type 'long long' but is of type 'int' |
16+
| printf1.h:148:19:148:20 | ui | This argument should be of type 'unsigned long long' but is of type 'unsigned int' |
1517
| real_world.h:61:21:61:22 | & ... | This argument should be of type 'int *' but is of type 'short *' |
1618
| real_world.h:62:22:62:23 | & ... | This argument should be of type 'short *' but is of type 'int *' |
1719
| 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_signed_chars/printf1.h

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,3 +134,20 @@ void extensions()
134134
printf("%llu", uli); // BAD (should be %lu) [NOT DETECTED]
135135
}
136136
}
137+
138+
void fun4()
139+
{
140+
int i;
141+
unsigned int ui;
142+
long l;
143+
unsigned long ul;
144+
long long ll;
145+
unsigned long long ull;
146+
147+
printf("%qi\n", i); // BAD
148+
printf("%qu\n", ui); // BAD
149+
printf("%qi\n", l); // GOOD
150+
printf("%qu\n", ul); // GOOD
151+
printf("%qi\n", ll); // GOOD
152+
printf("%qu\n", ull); // GOOD
153+
}

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313
| printf1.h:130:18:130:18 | 0 | This argument should be of type 'void *' but is of type 'int' |
1414
| printf1.h:154:18:154:19 | wc | This argument should be of type 'char *' but is of type 'wchar_t *' |
1515
| printf1.h:155:18:155:18 | c | This argument should be of type 'wchar_t *' but is of type 'char *' |
16+
| printf1.h:168:19:168:19 | i | This argument should be of type 'long long' but is of type 'int' |
17+
| printf1.h:169:19:169:20 | ui | This argument should be of type 'unsigned long long' but is of type 'unsigned int' |
1618
| real_world.h:61:21:61:22 | & ... | This argument should be of type 'int *' but is of type 'short *' |
1719
| real_world.h:62:22:62:23 | & ... | This argument should be of type 'short *' but is of type 'int *' |
1820
| 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: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,3 +155,20 @@ void test_ws(char *c, wchar_t *wc)
155155
wprintf(L"%S", c); // BAD
156156
wprintf(L"%S", wc); // GOOD
157157
}
158+
159+
void fun4()
160+
{
161+
int i;
162+
unsigned int ui;
163+
long l;
164+
unsigned long ul;
165+
long long ll;
166+
unsigned long long ull;
167+
168+
printf("%qi\n", i); // BAD
169+
printf("%qu\n", ui); // BAD
170+
printf("%qi\n", l); // GOOD
171+
printf("%qu\n", ul); // GOOD
172+
printf("%qi\n", ll); // GOOD
173+
printf("%qu\n", ull); // GOOD
174+
}

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,18 @@
2121
| printf1.h:130:18:130:18 | 0 | This argument should be of type 'void *' but is of type 'int' |
2222
| printf1.h:153:18:153:18 | c | This argument should be of type '__wchar_t *' but is of type 'char *' |
2323
| printf1.h:156:18:156:19 | wc | This argument should be of type 'char *' but is of type '__wchar_t *' |
24+
| printf1.h:174:19:174:21 | pdt | This argument should be of type 'int' but is of type 'long long' |
25+
| printf1.h:175:19:175:20 | sz | This argument should be of type 'unsigned int' but is of type 'unsigned long long' |
26+
| printf1.h:181:21:181:22 | ll | This argument should be of type 'int' but is of type 'long long' |
27+
| printf1.h:182:21:182:23 | ull | This argument should be of type 'unsigned int' but is of type 'unsigned long long' |
28+
| printf1.h:185:21:185:23 | i64 | This argument should be of type 'int' but is of type 'long long' |
29+
| printf1.h:186:21:186:23 | u64 | This argument should be of type 'unsigned int' but is of type 'unsigned long long' |
30+
| printf1.h:188:21:188:21 | i | This argument should be of type 'long long' but is of type 'int' |
31+
| printf1.h:189:21:189:22 | ui | This argument should be of type 'unsigned long long' but is of type 'unsigned int' |
32+
| printf1.h:190:21:190:21 | l | This argument should be of type 'long long' but is of type 'long' |
33+
| printf1.h:191:21:191:22 | ul | This argument should be of type 'unsigned long long' but is of type 'unsigned long' |
34+
| printf1.h:194:21:194:23 | i32 | This argument should be of type 'long long' but is of type 'int' |
35+
| printf1.h:195:21:195:23 | u32 | This argument should be of type 'unsigned long long' but is of type 'unsigned int' |
2436
| real_world.h:61:21:61:22 | & ... | This argument should be of type 'int *' but is of type 'short *' |
2537
| real_world.h:62:22:62:23 | & ... | This argument should be of type 'short *' but is of type 'int *' |
2638
| 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: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,3 +155,44 @@ void test_ws(char *c, wchar_t *wc, wint_t *wt)
155155
wprintf(L"%S", c); // GOOD
156156
wprintf(L"%S", wc); // BAD
157157
}
158+
159+
void fun4()
160+
{
161+
ptrdiff_t pdt;
162+
size_t sz;
163+
int i;
164+
unsigned int ui;
165+
long l;
166+
unsigned long ul;
167+
long long ll;
168+
unsigned long long ull;
169+
__int32 i32;
170+
unsigned __int32 u32;
171+
__int64 i64;
172+
unsigned __int64 u64;
173+
174+
printf("%Ii\n", pdt); // GOOD [FALSE POSITIVE]
175+
printf("%Iu\n", sz); // GOOD [FALSE POSITIVE]
176+
177+
printf("%I32i\n", i); // GOOD
178+
printf("%I32u\n", ui); // GOOD
179+
printf("%I32i\n", l); // GOOD
180+
printf("%I32u\n", ul); // GOOD
181+
printf("%I32i\n", ll); // BAD
182+
printf("%I32u\n", ull); // BAD
183+
printf("%I32i\n", i32); // GOOD
184+
printf("%I32u\n", u32); // GOOD
185+
printf("%I32i\n", i64); // BAD
186+
printf("%I32u\n", u64); // BAD
187+
188+
printf("%I64i\n", i); // BAD
189+
printf("%I64u\n", ui); // BAD
190+
printf("%I64i\n", l); // BAD
191+
printf("%I64u\n", ul); // BAD
192+
printf("%I64i\n", ll); // GOOD
193+
printf("%I64u\n", ull); // GOOD
194+
printf("%I64i\n", i32); // BAD
195+
printf("%I64u\n", u32); // BAD
196+
printf("%I64i\n", i64); // GOOD
197+
printf("%I64u\n", u64); // GOOD
198+
}

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,18 @@
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' |
1919
| printf1.h:130:18:130:18 | 0 | This argument should be of type 'void *' but is of type 'int' |
20+
| printf1.h:148:19:148:21 | pdt | This argument should be of type 'int' but is of type 'long long' |
21+
| printf1.h:149:19:149:20 | sz | This argument should be of type 'unsigned int' but is of type 'unsigned long long' |
22+
| printf1.h:155:21:155:22 | ll | This argument should be of type 'int' but is of type 'long long' |
23+
| printf1.h:156:21:156:23 | ull | This argument should be of type 'unsigned int' but is of type 'unsigned long long' |
24+
| printf1.h:159:21:159:23 | i64 | This argument should be of type 'int' but is of type 'long long' |
25+
| printf1.h:160:21:160:23 | u64 | This argument should be of type 'unsigned int' but is of type 'unsigned long long' |
26+
| printf1.h:162:21:162:21 | i | This argument should be of type 'long long' but is of type 'int' |
27+
| printf1.h:163:21:163:22 | ui | This argument should be of type 'unsigned long long' but is of type 'unsigned int' |
28+
| printf1.h:164:21:164:21 | l | This argument should be of type 'long long' but is of type 'long' |
29+
| printf1.h:165:21:165:22 | ul | This argument should be of type 'unsigned long long' but is of type 'unsigned long' |
30+
| printf1.h:168:21:168:23 | i32 | This argument should be of type 'long long' but is of type 'int' |
31+
| printf1.h:169:21:169:23 | u32 | This argument should be of type 'unsigned long long' but is of type 'unsigned int' |
2032
| real_world.h:61:21:61:22 | & ... | This argument should be of type 'int *' but is of type 'short *' |
2133
| real_world.h:62:22:62:23 | & ... | This argument should be of type 'short *' but is of type 'int *' |
2234
| 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_no_wchar/printf1.h

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,3 +129,44 @@ void fun3(void *p1, VOIDPTR p2, FUNPTR p3, char *p4)
129129
printf("%p\n", p4 + 1); // GOOD
130130
printf("%p\n", 0); // GOOD [FALSE POSITIVE]
131131
}
132+
133+
void fun4()
134+
{
135+
ptrdiff_t pdt;
136+
size_t sz;
137+
int i;
138+
unsigned int ui;
139+
long l;
140+
unsigned long ul;
141+
long long ll;
142+
unsigned long long ull;
143+
__int32 i32;
144+
unsigned __int32 u32;
145+
__int64 i64;
146+
unsigned __int64 u64;
147+
148+
printf("%Ii\n", pdt); // GOOD [FALSE POSITIVE]
149+
printf("%Iu\n", sz); // GOOD [FALSE POSITIVE]
150+
151+
printf("%I32i\n", i); // GOOD
152+
printf("%I32u\n", ui); // GOOD
153+
printf("%I32i\n", l); // GOOD
154+
printf("%I32u\n", ul); // GOOD
155+
printf("%I32i\n", ll); // BAD
156+
printf("%I32u\n", ull); // BAD
157+
printf("%I32i\n", i32); // GOOD
158+
printf("%I32u\n", u32); // GOOD
159+
printf("%I32i\n", i64); // BAD
160+
printf("%I32u\n", u64); // BAD
161+
162+
printf("%I64i\n", i); // BAD
163+
printf("%I64u\n", ui); // BAD
164+
printf("%I64i\n", l); // BAD
165+
printf("%I64u\n", ul); // BAD
166+
printf("%I64i\n", ll); // GOOD
167+
printf("%I64u\n", ull); // GOOD
168+
printf("%I64i\n", i32); // BAD
169+
printf("%I64u\n", u32); // BAD
170+
printf("%I64i\n", i64); // GOOD
171+
printf("%I64u\n", u64); // GOOD
172+
}

0 commit comments

Comments
 (0)