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

Skip to content

Commit 162c998

Browse files
committed
CPP: Add some test cases.
1 parent 752ca94 commit 162c998

4 files changed

Lines changed: 20 additions & 0 deletions

File tree

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
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:125:18:125:18 | c | This argument should be of type 'wchar_t *' but is of type 'char *' |
15+
| printf1.h:128:18:128:19 | wc | This argument should be of type 'char *' but is of type 'wchar_t *' |
1416
| real_world.h:61:21:61:22 | & ... | This argument should be of type 'int *' but is of type 'short *' |
1517
| real_world.h:62:22:62:23 | & ... | This argument should be of type 'short *' but is of type 'int *' |
1618
| 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_unsigned_chars/printf1.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,3 +119,11 @@ void test_chars(char c, wchar_t wc, wint_t wt)
119119
wprintf(L"%C", wc); // GOOD (converts to wint_t)
120120
wprintf(L"%C", wt); // GOOD
121121
}
122+
123+
void test_ws(char *c, wchar_t *wc)
124+
{
125+
wprintf(L"%s", c); // GOOD [FALSE POSITIVE]
126+
wprintf(L"%s", wc); // BAD [NOT DETECTED]
127+
wprintf(L"%S", c); // BAD [NOT DETECTED]
128+
wprintf(L"%S", wc); // GOOD [FALSE POSITIVE]
129+
}

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
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:125:18:125:18 | c | This argument should be of type '__wchar_t *' but is of type 'char *' |
21+
| printf1.h:128:18:128:19 | wc | This argument should be of type 'char *' but is of type '__wchar_t *' |
2022
| real_world.h:61:21:61:22 | & ... | This argument should be of type 'int *' but is of type 'short *' |
2123
| real_world.h:62:22:62:23 | & ... | This argument should be of type 'short *' but is of type 'int *' |
2224
| 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/Microsoft/printf1.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,3 +119,11 @@ void test_chars(char c, wchar_t wc, wint_t wt)
119119
wprintf(L"%C", wc); // BAD [NOT DETECTED]
120120
wprintf(L"%C", wt); // BAD [NOT DETECTED]
121121
}
122+
123+
void test_ws(char *c, wchar_t *wc, wint_t *wt)
124+
{
125+
wprintf(L"%s", c); // BAD [NOT DETECTED]
126+
wprintf(L"%s", wc); // GOOD
127+
wprintf(L"%S", c); // GOOD
128+
wprintf(L"%S", wc); // BAD [NOT DETECTED]
129+
}

0 commit comments

Comments
 (0)