mirror of
https://github.com/github/codeql.git
synced 2026-05-04 13:15:21 +02:00
CPP: Add a test where different wide types are present.
This commit is contained in:
@@ -0,0 +1,12 @@
|
||||
| tests.cpp:18:15:18:22 | Hello | This argument should be of type 'char *' but is of type 'char16_t *' |
|
||||
| tests.cpp:19:15:19:22 | Hello | This argument should be of type 'char *' but is of type 'wchar_t *' |
|
||||
| tests.cpp:21:15:21:21 | Hello | This argument should be of type 'wchar_t *' but is of type 'char *' |
|
||||
| tests.cpp:22:15:22:22 | Hello | This argument should be of type 'wchar_t *' but is of type 'char16_t *' |
|
||||
| tests.cpp:25:17:25:23 | Hello | This argument should be of type 'wchar_t *' but is of type 'char *' |
|
||||
| tests.cpp:26:17:26:24 | Hello | This argument should be of type 'wchar_t *' but is of type 'char16_t *' |
|
||||
| tests.cpp:30:17:30:24 | Hello | This argument should be of type 'char *' but is of type 'char16_t *' |
|
||||
| tests.cpp:31:17:31:24 | Hello | This argument should be of type 'char *' but is of type 'wchar_t *' |
|
||||
| tests.cpp:33:36:33:42 | Hello | This argument should be of type 'wchar_t *' but is of type 'char *' |
|
||||
| tests.cpp:34:36:34:43 | Hello | This argument should be of type 'wchar_t *' but is of type 'char16_t *' |
|
||||
| tests.cpp:38:36:38:43 | Hello | This argument should be of type 'char *' but is of type 'char16_t *' |
|
||||
| tests.cpp:39:36:39:43 | Hello | This argument should be of type 'char *' but is of type 'wchar_t *' |
|
||||
@@ -0,0 +1 @@
|
||||
Likely Bugs/Format/WrongTypeFormatArguments.ql
|
||||
@@ -0,0 +1,40 @@
|
||||
/*
|
||||
* Test for custom definitions of *wprintf using different types than the
|
||||
* platform wide character type.
|
||||
*/
|
||||
|
||||
typedef unsigned int size_t;
|
||||
|
||||
int printf(const char * format, ...);
|
||||
int wprintf(const wchar_t * format, ...); // on wchar_t
|
||||
int swprintf(char16_t * s, size_t n, const char16_t * format, ...); // on char16_t
|
||||
|
||||
#define BUF_SIZE (4096)
|
||||
|
||||
void tests() {
|
||||
char16_t buffer[BUF_SIZE];
|
||||
|
||||
printf("%s", "Hello"); // GOOD
|
||||
printf("%s", u"Hello"); // BAD: expecting char
|
||||
printf("%s", L"Hello"); // BAD: expecting char
|
||||
|
||||
printf("%S", "Hello"); // BAD: expecting wchar_t or char16_t
|
||||
printf("%S", u"Hello"); // GOOD [FALSE POSITIVE]
|
||||
printf("%S", L"Hello"); // GOOD
|
||||
|
||||
wprintf(L"%s", "Hello"); // BAD: expecting wchar_t
|
||||
wprintf(L"%s", u"Hello"); // BAD: expecting wchar_t
|
||||
wprintf(L"%s", L"Hello"); // GOOD
|
||||
|
||||
wprintf(L"%S", "Hello"); // GOOD
|
||||
wprintf(L"%S", u"Hello"); // BAD: expecting char
|
||||
wprintf(L"%S", L"Hello"); // BAD: expecting char
|
||||
|
||||
swprintf(buffer, BUF_SIZE, u"%s", "Hello"); // BAD: expecting char16_t
|
||||
swprintf(buffer, BUF_SIZE, u"%s", u"Hello"); // GOOD [FALSE POSITIVE]
|
||||
swprintf(buffer, BUF_SIZE, u"%s", L"Hello"); // BAD: expecting char16_t [NOT DETECTED]
|
||||
|
||||
swprintf(buffer, BUF_SIZE, u"%S", "Hello"); // GOOD
|
||||
swprintf(buffer, BUF_SIZE, u"%S", u"Hello"); // BAD: expecting char
|
||||
swprintf(buffer, BUF_SIZE, u"%S", L"Hello"); // BAD: expecting char
|
||||
}
|
||||
Reference in New Issue
Block a user