Skip to content

Commit 66e87fc

Browse files
committed
CPP: Detect Microsoft compilations even more reliably.
1 parent 5911699 commit 66e87fc

File tree

4 files changed

+11
-7
lines changed

4 files changed

+11
-7
lines changed

cpp/ql/src/semmle/code/cpp/File.qll

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -306,6 +306,9 @@ class File extends Container, @file {
306306
c.getAnArgument() = "--microsoft" or
307307
c.getAnArgument().matches("%\\\\cl.exe")
308308
)
309+
) or exists(File parent |
310+
parent.compiledAsMicrosoft() and
311+
parent.getAnIncludedFile() = this
309312
)
310313
}
311314

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,11 @@
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:126:18:126:19 | wc | This argument should be of type 'char *' but is of type '__wchar_t *' |
21-
| printf1.h:127:18:127:18 | c | This argument should be of type '__wchar_t *' but is of type 'char *' |
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 *' |
2222
| real_world.h:61:21:61:22 | & ... | This argument should be of type 'int *' but is of type 'short *' |
2323
| real_world.h:62:22:62:23 | & ... | This argument should be of type 'short *' but is of type 'int *' |
2424
| real_world.h:63:22:63:24 | & ... | This argument should be of type 'short *' but is of type 'unsigned int *' |
2525
| real_world.h:64:22:64:24 | & ... | This argument should be of type 'short *' but is of type 'signed int *' |
2626
| wide_string.h:25:18:25:20 | c | This argument should be of type 'char' but is of type 'char *' |
27+
| wide_string.h:29:19:29:22 | c | This argument should be of type 'wchar_t' but is of type '__wchar_t *' |

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -122,8 +122,8 @@ void test_chars(char c, wchar_t wc, wint_t wt)
122122

123123
void test_ws(char *c, wchar_t *wc, wint_t *wt)
124124
{
125-
wprintf(L"%s", c); // BAD [NOT DETECTED]
126-
wprintf(L"%s", wc); // GOOD [FALSE POSITIVE]
127-
wprintf(L"%S", c); // GOOD [FALSE POSITIVE]
128-
wprintf(L"%S", wc); // BAD [NOT DETECTED]
125+
wprintf(L"%s", c); // BAD
126+
wprintf(L"%s", wc); // GOOD
127+
wprintf(L"%S", c); // GOOD
128+
wprintf(L"%S", wc); // BAD
129129
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,5 +26,5 @@ void test_wchar4(char c, const char cc, wchar_t wc, const wchar_t wcc) {
2626
printf("%wc", wc); // GOOD
2727
printf("%wc", wcc); // GOOD
2828
printf("%wc", L'c'); // GOOD
29-
printf("%wc", L"c"); // BAD [NOT DETECTED]
29+
printf("%wc", L"c"); // BAD
3030
}

0 commit comments

Comments
 (0)