mirror of
https://github.com/github/codeql.git
synced 2026-05-04 13:15:21 +02:00
C++: Autoformat everything
Some files that will change in #1736 have been spared. ./build -j4 target/jars/qlformat find ql/cpp/ql -name "*.ql" -print0 | xargs -0 target/jars/qlformat --input find ql/cpp/ql -name "*.qll" -print0 | xargs -0 target/jars/qlformat --input (cd ql && git checkout 'cpp/ql/src/semmle/code/cpp/ir/implementation/**/*SSA*.qll') buildutils-internal/scripts/pr-checks/sync-identical-files.py --latest
This commit is contained in:
@@ -7,15 +7,16 @@
|
||||
* @problem.severity warning
|
||||
* @tags reliability
|
||||
*/
|
||||
|
||||
import cpp
|
||||
import SAL
|
||||
|
||||
from Parameter p, Call c, Expr arg
|
||||
where any(SALNotNull a).getDeclaration() = p
|
||||
and c.getTarget() = p.getFunction()
|
||||
and arg = c.getArgument(p.getIndex())
|
||||
and nullValue(arg)
|
||||
select arg, "Argument ("+ arg.toString()
|
||||
+") for parameter $@ in call to "+ c.getTarget().getName() +
|
||||
" may be null, but a SAL annotation forbids this.",
|
||||
p, p.getName()
|
||||
where
|
||||
any(SALNotNull a).getDeclaration() = p and
|
||||
c.getTarget() = p.getFunction() and
|
||||
arg = c.getArgument(p.getIndex()) and
|
||||
nullValue(arg)
|
||||
select arg,
|
||||
"Argument (" + arg.toString() + ") for parameter $@ in call to " + c.getTarget().getName() +
|
||||
" may be null, but a SAL annotation forbids this.", p, p.getName()
|
||||
|
||||
@@ -8,12 +8,14 @@
|
||||
* @problem.severity warning
|
||||
* @tags reliability
|
||||
*/
|
||||
|
||||
import SAL
|
||||
|
||||
from Function f, FunctionCall call
|
||||
where call.getTarget() = f
|
||||
and call instanceof ExprInVoidContext
|
||||
and any(SALCheckReturn a).getDeclaration() = f
|
||||
and not getOptions().okToIgnoreReturnValue(call)
|
||||
select call, "Return value of $@ discarded although a SAL annotation "+
|
||||
"requires inspecting it.", f, f.getName()
|
||||
where
|
||||
call.getTarget() = f and
|
||||
call instanceof ExprInVoidContext and
|
||||
any(SALCheckReturn a).getDeclaration() = f and
|
||||
not getOptions().okToIgnoreReturnValue(call)
|
||||
select call, "Return value of $@ discarded although a SAL annotation " + "requires inspecting it.",
|
||||
f, f.getName()
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
* @problem.severity warning
|
||||
* @tags reliability
|
||||
*/
|
||||
|
||||
import SAL
|
||||
|
||||
/** Holds if `e` has SAL annotation `name`. */
|
||||
@@ -25,16 +26,16 @@ predicate inheritsDeclAnnotations(DeclarationEntry e) {
|
||||
)
|
||||
or
|
||||
// or is a parameter of a function with such an annotation
|
||||
inheritsDeclAnnotations(e.(ParameterDeclarationEntry)
|
||||
.getFunctionDeclarationEntry())
|
||||
inheritsDeclAnnotations(e.(ParameterDeclarationEntry).getFunctionDeclarationEntry())
|
||||
}
|
||||
|
||||
from DeclarationEntry e1, DeclarationEntry e2, string name
|
||||
where e1.getDeclaration() = e2.getDeclaration()
|
||||
and hasAnnotation(e1, name)
|
||||
and not hasAnnotation(e2, name)
|
||||
and not name = "_Use_decl_annotations_"
|
||||
and not inheritsDeclAnnotations(e2)
|
||||
select e2, "Missing SAL annotation "+ name +
|
||||
" in "+ e2.toString() +" although it is present on $@.",
|
||||
e1, e1.toString()
|
||||
where
|
||||
e1.getDeclaration() = e2.getDeclaration() and
|
||||
hasAnnotation(e1, name) and
|
||||
not hasAnnotation(e2, name) and
|
||||
not name = "_Use_decl_annotations_" and
|
||||
not inheritsDeclAnnotations(e2)
|
||||
select e2,
|
||||
"Missing SAL annotation " + name + " in " + e2.toString() + " although it is present on $@.", e1,
|
||||
e1.toString()
|
||||
|
||||
@@ -15,14 +15,10 @@ class SALAnnotation extends MacroInvocation {
|
||||
}
|
||||
|
||||
/** Returns the `Declaration` annotated by `this`. */
|
||||
Declaration getDeclaration() {
|
||||
annotatesAt(this, result.getADeclarationEntry(), _, _)
|
||||
}
|
||||
Declaration getDeclaration() { annotatesAt(this, result.getADeclarationEntry(), _, _) }
|
||||
|
||||
/** Returns the `DeclarationEntry` annotated by `this`. */
|
||||
DeclarationEntry getDeclarationEntry() {
|
||||
annotatesAt(this, result, _, _)
|
||||
}
|
||||
DeclarationEntry getDeclarationEntry() { annotatesAt(this, result, _, _) }
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -47,12 +43,12 @@ class SALNotNull extends SALAnnotation {
|
||||
m.getName().matches("\\_Out%") or
|
||||
m.getName() = "_Ret_notnull_"
|
||||
)
|
||||
)
|
||||
and
|
||||
exists(Type t
|
||||
| t = this.getDeclaration().(Variable).getType() or
|
||||
) and
|
||||
exists(Type t |
|
||||
t = this.getDeclaration().(Variable).getType() or
|
||||
t = this.getDeclaration().(Function).getType()
|
||||
| t.getUnspecifiedType() instanceof PointerType
|
||||
|
|
||||
t.getUnspecifiedType() instanceof PointerType
|
||||
)
|
||||
}
|
||||
}
|
||||
@@ -60,9 +56,9 @@ class SALNotNull extends SALAnnotation {
|
||||
class SALMaybeNull extends SALAnnotation {
|
||||
SALMaybeNull() {
|
||||
exists(SALMacro m | m = this.getMacro() |
|
||||
m.getName().matches("%\\_opt\\_%") or
|
||||
m.getName().matches("\\_Ret_maybenull\\_%") or
|
||||
m.getName() = "_Result_nullonfailure_"
|
||||
m.getName().matches("%\\_opt\\_%") or
|
||||
m.getName().matches("\\_Ret_maybenull\\_%") or
|
||||
m.getName() = "_Result_nullonfailure_"
|
||||
)
|
||||
}
|
||||
}
|
||||
@@ -71,8 +67,7 @@ class SALMaybeNull extends SALAnnotation {
|
||||
* Implementation details
|
||||
*/
|
||||
|
||||
private predicate annotatesAt(SALAnnotation a, DeclarationEntry e,
|
||||
File file, int idx) {
|
||||
private predicate annotatesAt(SALAnnotation a, DeclarationEntry e, File file, int idx) {
|
||||
a = salElementAt(file, idx) and
|
||||
(
|
||||
// Base case: `a` right before `e`
|
||||
@@ -95,8 +90,10 @@ private SALElement salElementAt(File file, int idx) {
|
||||
interestingLoc(file, result, interestingStartPos(file, idx))
|
||||
}
|
||||
|
||||
/** Holds if an SALElement element at character `result` comes at
|
||||
* position `idx` in `file`. */
|
||||
/**
|
||||
* Holds if an SALElement element at character `result` comes at
|
||||
* position `idx` in `file`.
|
||||
*/
|
||||
private int interestingStartPos(File file, int idx) {
|
||||
result = rank[idx](int otherStart | interestingLoc(file, _, otherStart))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user