Skip to content

Commit b3fd7ab

Browse files
committed
CPP: Add test cases.
1 parent 02f4695 commit b3fd7ab

File tree

2 files changed

+39
-0
lines changed

2 files changed

+39
-0
lines changed

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,12 @@
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' |
1313
| printf1.h:47:19:47:21 | ull | This argument should be of type 'unsigned int' but is of type 'unsigned long long' |
14+
| printf1.h:112:18:112:19 | ld | This argument should be of type 'double' but is of type 'long double' |
15+
| printf1.h:113:17:113:17 | d | This argument should be of type 'long double' but is of type 'double' |
16+
| printf1.h:122:17:122:19 | lli | This argument should be of type 'int' but is of type 'long long' |
17+
| printf1.h:123:17:123:18 | li | This argument should be of type 'int' but is of type 'long' |
18+
| printf1.h:132:17:132:20 | ulli | This argument should be of type 'unsigned int' but is of type 'unsigned long long' |
19+
| printf1.h:133:17:133:19 | uli | This argument should be of type 'unsigned int' but is of type 'unsigned long' |
1420
| real_world.h:61:21:61:22 | & ... | This argument should be of type 'int *' but is of type 'short *' |
1521
| real_world.h:62:22:62:23 | & ... | This argument should be of type 'short *' but is of type 'int *' |
1622
| 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: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,3 +101,36 @@ void fun1(unsigned char* a, unsigned char* b) {
101101
printf("%td\n", pdt); // GOOD
102102
printf("%td\n", a-b); // GOOD
103103
}
104+
105+
void extensions()
106+
{
107+
{
108+
long double ld;
109+
double d;
110+
111+
printf("%Lg", ld); // GOOD
112+
printf("%llg", ld); // GOOD (nonstandard equivalent to %Lg) [FALSE POSITIVE]
113+
printf("%Lg", d); // BAD (should be %g)
114+
printf("%llg", d); // BAD (should be %g) [NOT DETECTED]
115+
}
116+
117+
{
118+
long long int lli;
119+
long int li;
120+
121+
printf("%lld", lli); // GOOD
122+
printf("%Ld", lli); // GOOD (nonstandard equivalent to %lld) [FALSE POSITIVE]
123+
printf("%Ld", li); // BAD (should be %ld)
124+
printf("%lld", li); // BAD (should be %ld) [NOT DETECTED]
125+
}
126+
127+
{
128+
unsigned long long int ulli;
129+
unsigned long int uli;
130+
131+
printf("%llu", ulli); // GOOD
132+
printf("%Lu", ulli); // GOOD (nonstandard equivalent to %llu) [FALSE POSITIVE]
133+
printf("%Lu", uli); // BAD (should be %lu)
134+
printf("%llu", uli); // BAD (should be %lu) [NOT DETECTED]
135+
}
136+
}

0 commit comments

Comments
 (0)