Skip to content

Commit a9b3c0d

Browse files
committed
C++: Address review comments
1 parent fe00c88 commit a9b3c0d

File tree

5 files changed

+8
-13
lines changed

5 files changed

+8
-13
lines changed

cpp/ql/lib/semmle/code/cpp/Function.qll

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -505,8 +505,11 @@ class Function extends Declaration, ControlFlowNode, AccessHolder, @function {
505505
* Holds if this function has extraction errors that create an `ErrorExpr`.
506506
*/
507507
predicate hasErrors() {
508-
// Exclude allocator call arguments because they are are always extracted as `ErrorExpr`.
509-
exists(ErrorExpr e | e.getEnclosingFunction() = this and not e.isFirstAllocatorCallArgument())
508+
exists(ErrorExpr e |
509+
e.getEnclosingFunction() = this and
510+
// Exclude the first allocator call argument because it is always extracted as `ErrorExpr`.
511+
not exists(NewOrNewArrayExpr new | e = new.getAllocatorCall().getArgument(0))
512+
)
510513
}
511514
}
512515

cpp/ql/lib/semmle/code/cpp/exprs/Expr.qll

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -744,13 +744,6 @@ class ErrorExpr extends Expr, @errorexpr {
744744
override string toString() { result = "<error expr>" }
745745

746746
override string getAPrimaryQlClass() { result = "ErrorExpr" }
747-
748-
/**
749-
* Holds if this error expression is the first argument to a `new` allocation call.
750-
*/
751-
predicate isFirstAllocatorCallArgument() {
752-
this = any(NewOrNewArrayExpr new).getAllocatorCall().getArgument(0)
753-
}
754747
}
755748

756749
/**

cpp/ql/lib/semmle/code/cpp/ir/implementation/raw/internal/TranslatedElement.qll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ private predicate ignoreExprOnly(Expr expr) {
151151
// The extractor deliberately emits an `ErrorExpr` as the first argument to
152152
// the allocator call, if any, of a `NewOrNewArrayExpr`. That `ErrorExpr`
153153
// should not be translated.
154-
expr.(ErrorExpr).isFirstAllocatorCallArgument()
154+
exists(NewOrNewArrayExpr new | expr = new.getAllocatorCall().getArgument(0))
155155
or
156156
not translateFunction(getEnclosingFunction(expr)) and
157157
not Raw::varHasIRFunc(getEnclosingVariable(expr))

cpp/ql/src/Likely Bugs/Memory Management/UninitializedLocal.ql

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ predicate isSinkImpl(Instruction sink, VariableAccess va) {
6565
exists(LoadInstruction load |
6666
va = load.getUnconvertedResultExpression() and
6767
not va = commonException() and
68+
not va.getTarget().(LocalVariable).getFunction().hasErrors() and
6869
sink = load.getSourceValue()
6970
)
7071
}
@@ -89,6 +90,5 @@ from
8990
where
9091
conf.hasFlowPath(source, sink) and
9192
isSinkImpl(sink.getInstruction(), va) and
92-
v = va.getTarget() and
93-
not v.getFunction().hasErrors()
93+
v = va.getTarget()
9494
select va, source, sink, "The variable $@ may not be initialized at this access.", v, v.getName()

cpp/ql/test/query-tests/Security/CWE/CWE-457/semmle/tests/UninitializedLocal.expected

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
edges
22
nodes
3-
| errors.cpp:4:7:4:7 | definition of x | semmle.label | definition of x |
43
| errors.cpp:13:7:13:7 | definition of x | semmle.label | definition of x |
54
| test.cpp:11:6:11:8 | definition of foo | semmle.label | definition of foo |
65
| test.cpp:111:6:111:8 | definition of foo | semmle.label | definition of foo |

0 commit comments

Comments
 (0)