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

Skip to content

Commit 5911699

Browse files
committed
CPP: Clean up some remaining old 'isWideCharDefault' logic that has caused confusion.
1 parent eef050d commit 5911699

2 files changed

Lines changed: 10 additions & 12 deletions

File tree

cpp/ql/src/semmle/code/cpp/commons/Printf.qll

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -32,19 +32,19 @@ class AttributeFormattingFunction extends FormattingFunction {
3232
* A standard function such as `vprintf` that has a format parameter
3333
* and a variable argument list of type `va_arg`.
3434
*/
35-
predicate primitiveVariadicFormatter(TopLevelFunction f, int formatParamIndex, boolean wide) {
35+
predicate primitiveVariadicFormatter(TopLevelFunction f, int formatParamIndex) {
3636
f.getName().regexpMatch("_?_?va?[fs]?n?w?printf(_s)?(_p)?(_l)?")
3737
and (
3838
if f.getName().matches("%\\_l")
3939
then formatParamIndex = f.getNumberOfParameters() - 3
4040
else formatParamIndex = f.getNumberOfParameters() - 2
41-
) and if f.getName().matches("%w%") then wide = true else wide = false
41+
)
4242
}
4343

4444
private
45-
predicate callsVariadicFormatter(Function f, int formatParamIndex, boolean wide) {
45+
predicate callsVariadicFormatter(Function f, int formatParamIndex) {
4646
exists(FunctionCall fc, int i |
47-
variadicFormatter(fc.getTarget(), i, wide)
47+
variadicFormatter(fc.getTarget(), i)
4848
and fc.getEnclosingFunction() = f
4949
and fc.getArgument(i) = f.getParameter(formatParamIndex).getAnAccess()
5050
)
@@ -54,11 +54,11 @@ predicate callsVariadicFormatter(Function f, int formatParamIndex, boolean wide)
5454
* Holds if `f` is a function such as `vprintf` that has a format parameter
5555
* (at `formatParamIndex`) and a variable argument list of type `va_arg`.
5656
*/
57-
predicate variadicFormatter(Function f, int formatParamIndex, boolean wide) {
58-
primitiveVariadicFormatter(f, formatParamIndex, wide)
57+
predicate variadicFormatter(Function f, int formatParamIndex) {
58+
primitiveVariadicFormatter(f, formatParamIndex)
5959
or (
6060
not f.isVarargs()
61-
and callsVariadicFormatter(f, formatParamIndex, wide)
61+
and callsVariadicFormatter(f, formatParamIndex)
6262
)
6363
}
6464

@@ -68,12 +68,10 @@ predicate variadicFormatter(Function f, int formatParamIndex, boolean wide) {
6868
*/
6969
class UserDefinedFormattingFunction extends FormattingFunction {
7070
UserDefinedFormattingFunction() {
71-
isVarargs() and callsVariadicFormatter(this, _, _)
71+
isVarargs() and callsVariadicFormatter(this, _)
7272
}
7373

74-
override int getFormatParameterIndex() { callsVariadicFormatter(this, result, _) }
75-
76-
override predicate isWideCharDefault() { callsVariadicFormatter(this, _, true) }
74+
override int getFormatParameterIndex() { callsVariadicFormatter(this, result) }
7775
}
7876

7977
/**

cpp/ql/src/semmle/code/cpp/security/PrintfLike.qll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import external.ExternalArtifact
44
predicate printfLikeFunction(Function func, int formatArg) {
55
(formatArg = func.(FormattingFunction).getFormatParameterIndex() and not func instanceof UserDefinedFormattingFunction)
66
or
7-
primitiveVariadicFormatter(func, formatArg, _)
7+
primitiveVariadicFormatter(func, formatArg)
88
or
99
exists(ExternalData data |
1010
// TODO Do this \ to / conversion in the toolchain?

0 commit comments

Comments
 (0)