Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 1af6c10

Browse files
committed
CPP: Add a test where different word sizes are present.
1 parent 8005558 commit 1af6c10

4 files changed

Lines changed: 39 additions & 0 deletions

File tree

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
| tests_32.cpp:14:16:14:23 | void_ptr | This argument should be of type 'long' but is of type 'void *' |
2+
| tests_32.cpp:15:15:15:15 | l | This argument should be of type 'void *' but is of type 'long' |
3+
| tests_64.cpp:14:16:14:23 | void_ptr | This argument should be of type 'long' but is of type 'void *' |
4+
| tests_64.cpp:15:15:15:15 | l | This argument should be of type 'void *' but is of type 'long' |
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Likely Bugs/Format/WrongTypeFormatArguments.ql
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// semmle-extractor-options: --edg --target --edg linux_i686
2+
/*
3+
* Test for printf in a snapshot that contains multiple word/pointer sizes.
4+
*/
5+
6+
int printf(const char * format, ...);
7+
8+
void test_32()
9+
{
10+
long l;
11+
void *void_ptr;
12+
13+
printf("%li", l); // GOOD
14+
printf("%li", void_ptr); // BAD
15+
printf("%p", l); // BAD
16+
printf("%p", void_ptr); // GOOD
17+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// semmle-extractor-options: --edg --target --edg linux_x86_64
2+
/*
3+
* Test for printf in a snapshot that contains multiple word/pointer sizes.
4+
*/
5+
6+
int printf(const char * format, ...);
7+
8+
void test_64()
9+
{
10+
long l;
11+
void *void_ptr;
12+
13+
printf("%li", l); // GOOD
14+
printf("%li", void_ptr); // BAD
15+
printf("%p", l); // BAD
16+
printf("%p", void_ptr); // GOOD
17+
}

0 commit comments

Comments
 (0)