Skip to content

Commit c8caca3

Browse files
committed
CPP: Add test cases for %ls, %hs.
1 parent f5a7d7a commit c8caca3

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,7 @@
88
| tests.cpp:35:36:35:43 | Hello | This argument should be of type 'char *' but is of type 'wchar_t *' |
99
| tests.cpp:37:36:37:42 | Hello | This argument should be of type 'char16_t *' but is of type 'char *' |
1010
| tests.cpp:39:36:39:43 | Hello | This argument should be of type 'char16_t *' but is of type 'wchar_t *' |
11+
| tests.cpp:42:37:42:44 | Hello | This argument should be of type 'char *' but is of type 'char16_t *' |
12+
| tests.cpp:43:37:43:44 | Hello | This argument should be of type 'char *' but is of type 'wchar_t *' |
13+
| tests.cpp:45:37:45:43 | Hello | This argument should be of type 'char16_t *' but is of type 'char *' |
14+
| tests.cpp:47:37:47:44 | Hello | This argument should be of type 'char16_t *' but is of type 'wchar_t *' |

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,4 +37,12 @@ void tests() {
3737
swprintf(buffer, BUF_SIZE, u"%S", "Hello"); // BAD: expecting char16_t
3838
swprintf(buffer, BUF_SIZE, u"%S", u"Hello"); // GOOD
3939
swprintf(buffer, BUF_SIZE, u"%S", L"Hello"); // BAD: expecting char16_t
40+
41+
swprintf(buffer, BUF_SIZE, u"%hs", "Hello"); // GOOD
42+
swprintf(buffer, BUF_SIZE, u"%hs", u"Hello"); // BAD: expecting char
43+
swprintf(buffer, BUF_SIZE, u"%hs", L"Hello"); // BAD: expecting char
44+
45+
swprintf(buffer, BUF_SIZE, u"%ls", "Hello"); // BAD: expecting char16_t
46+
swprintf(buffer, BUF_SIZE, u"%ls", u"Hello"); // GOOD
47+
swprintf(buffer, BUF_SIZE, u"%ls", L"Hello"); // BAD: expecting char16_t
4048
}

0 commit comments

Comments
 (0)