mirror of
https://github.com/github/codeql.git
synced 2026-04-30 11:15:13 +02:00
CPP: Add FormattingFunction.getFormatCharType() and test.
This commit is contained in:
@@ -54,6 +54,18 @@ abstract class FormattingFunction extends Function {
|
||||
*/
|
||||
deprecated predicate isWideCharDefault() { none() }
|
||||
|
||||
/**
|
||||
* Gets the character type used in the format string for this function.
|
||||
*/
|
||||
Type getFormatCharType() {
|
||||
result =
|
||||
stripTopLevelSpecifiersOnly(
|
||||
stripTopLevelSpecifiersOnly(
|
||||
getParameter(getFormatParameterIndex()).getType().getUnderlyingType()
|
||||
).(PointerType).getBaseType()
|
||||
)
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the default character type expected for `%s` by this function. Typically
|
||||
* `char` or `wchar_t`.
|
||||
|
||||
@@ -1,3 +1,3 @@
|
||||
| tests.cpp:8:5:8:10 | printf | char | char16_t, wchar_t | char16_t, wchar_t |
|
||||
| tests.cpp:9:5:9:11 | wprintf | wchar_t | char | wchar_t |
|
||||
| tests.cpp:10:5:10:12 | swprintf | char16_t | char | char16_t |
|
||||
| tests.cpp:8:5:8:10 | printf | char | char | char16_t, wchar_t | char16_t, wchar_t |
|
||||
| tests.cpp:9:5:9:11 | wprintf | wchar_t | wchar_t | char | wchar_t |
|
||||
| tests.cpp:10:5:10:12 | swprintf | char16_t | char16_t | char | char16_t |
|
||||
|
||||
@@ -3,6 +3,7 @@ import cpp
|
||||
from FormattingFunction f
|
||||
select
|
||||
f,
|
||||
concat(f.getFormatCharType().toString(), ", "),
|
||||
concat(f.getDefaultCharType().toString(), ", "),
|
||||
concat(f.getNonDefaultCharType().toString(), ", "),
|
||||
concat(f.getWideCharType().toString(), ", ")
|
||||
|
||||
Reference in New Issue
Block a user