CPP: Add FormattingFunction.getFormatCharType() and test.

This commit is contained in:
Geoffrey White
2019-03-14 17:56:40 +00:00
parent 162c9981bd
commit 648cdbab6c
3 changed files with 16 additions and 3 deletions

View File

@@ -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`.

View File

@@ -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 |

View File

@@ -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(), ", ")