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

Skip to content

Commit 8005558

Browse files
committed
CPP: More test cases.
1 parent 2af56b8 commit 8005558

2 files changed

Lines changed: 29 additions & 0 deletions

File tree

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
| printf1.h:74:19:74:22 | C_ST | This argument should be of type 'ssize_t' but is of type 'unsigned long long' |
1818
| printf1.h:75:19:75:28 | sizeof(<expr>) | This argument should be of type 'ssize_t' but is of type 'unsigned long long' |
1919
| printf1.h:84:23:84:35 | ... - ... | This argument should be of type 'ssize_t' but is of type 'long long' |
20+
| printf1.h:130:18:130:18 | 0 | This argument should be of type 'void *' but is of type 'int' |
2021
| real_world.h:46:36:46:43 | filename | This argument should be of type 'wchar_t *' but is of type 'char16_t *' |
2122
| real_world.h:61:21:61:22 | & ... | This argument should be of type 'int *' but is of type 'short *' |
2223
| real_world.h:62:22:62:23 | & ... | This argument should be of type 'short *' but is of type 'int *' |

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

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,3 +101,31 @@ void fun1(unsigned char* a, unsigned char* b) {
101101
printf("%td\n", pdt); // GOOD
102102
printf("%td\n", a-b); // GOOD
103103
}
104+
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+
}

0 commit comments

Comments
 (0)