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

Skip to content

Commit b8e6ad8

Browse files
committed
C++: Introduce new predicate for better performance in models.
1 parent a5632b2 commit b8e6ad8

2 files changed

Lines changed: 13 additions & 1 deletion

File tree

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -334,6 +334,18 @@ class Function extends Declaration, ControlFlowNode, AccessHolder, @function {
334334
)
335335
}
336336

337+
/**
338+
* Gets the class of which this function, called `name`, is a member.
339+
*
340+
* Prefer to use `getDeclaringType()` or `getName()` directly if you do not
341+
* need to reason about both.
342+
*/
343+
pragma[nomagic]
344+
Class getClassAndName(string myName) {
345+
this.hasName(myName) and
346+
this.getDeclaringType() = result
347+
}
348+
337349
/**
338350
* Implements `ControlFlowNode.getControlFlowScope`. The `Function` is
339351
* used to represent the exit node of the control flow graph, so it is

cpp/ql/src/semmle/code/cpp/models/implementations/StdString.qll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ private class StdStringConstructor extends Constructor, TaintFunction {
6969
* The `std::string` function `c_str`.
7070
*/
7171
private class StdStringCStr extends TaintFunction {
72-
StdStringCStr() { this.getDeclaringType() instanceof StdBasicString and this.hasName("c_str") }
72+
StdStringCStr() { this.getClassAndName("c_str") instanceof StdBasicString }
7373

7474
override predicate hasTaintFlow(FunctionInput input, FunctionOutput output) {
7575
// flow from string itself (qualifier) to return value

0 commit comments

Comments
 (0)