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

Skip to content

Commit f8a1fb1

Browse files
committed
C++: Apply the new pattern where it doesn't matter for performance as well, for consistency.
1 parent bfef1a2 commit f8a1fb1

1 file changed

Lines changed: 8 additions & 17 deletions

File tree

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

Lines changed: 8 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -113,9 +113,7 @@ private class StdStringPush extends TaintFunction {
113113
* The `std::string` functions `front` and `back`.
114114
*/
115115
private class StdStringFrontBack extends TaintFunction {
116-
StdStringFrontBack() {
117-
this.getDeclaringType() instanceof StdBasicString and this.hasName(["front", "back"])
118-
}
116+
StdStringFrontBack() { this.getClassAndName(["front", "back"]) instanceof StdBasicString }
119117

120118
override predicate hasTaintFlow(FunctionInput input, FunctionOutput output) {
121119
// flow from object to returned reference
@@ -150,8 +148,7 @@ private class StdStringPlus extends TaintFunction {
150148
*/
151149
private class StdStringAppend extends TaintFunction {
152150
StdStringAppend() {
153-
this.getDeclaringType() instanceof StdBasicString and
154-
this.hasName(["operator+=", "append", "insert", "replace"])
151+
this.getClassAndName(["operator+=", "append", "insert", "replace"]) instanceof StdBasicString
155152
}
156153

157154
/**
@@ -266,9 +263,7 @@ private class StdBasicStringStream extends ClassTemplateInstantiation {
266263
* The `std::string` functions `at` and `operator[]`.
267264
*/
268265
private class StdStringAt extends TaintFunction {
269-
StdStringAt() {
270-
this.getDeclaringType() instanceof StdBasicString and this.hasName(["at", "operator[]"])
271-
}
266+
StdStringAt() { this.getClassAndName(["at", "operator[]"]) instanceof StdBasicString }
272267

273268
override predicate hasTaintFlow(FunctionInput input, FunctionOutput output) {
274269
// flow from qualifier to referenced return value
@@ -342,8 +337,7 @@ private class StdIStreamInNonMember extends DataFlowFunction, TaintFunction {
342337
*/
343338
private class StdIStreamGet extends TaintFunction {
344339
StdIStreamGet() {
345-
this.getDeclaringType() instanceof StdBasicIStream and
346-
this.hasName(["get", "peek"]) and
340+
this.getClassAndName(["get", "peek"]) instanceof StdBasicIStream and
347341
this.getNumberOfParameters() = 0
348342
}
349343

@@ -359,8 +353,7 @@ private class StdIStreamGet extends TaintFunction {
359353
*/
360354
private class StdIStreamRead extends DataFlowFunction, TaintFunction {
361355
StdIStreamRead() {
362-
this.getDeclaringType() instanceof StdBasicIStream and
363-
this.hasName(["get", "read"]) and
356+
this.getClassAndName(["get", "read"]) instanceof StdBasicIStream and
364357
this.getNumberOfParameters() > 0
365358
}
366359

@@ -486,8 +479,7 @@ private class StdBasicOStream extends ClassTemplateInstantiation {
486479
*/
487480
private class StdOStreamOut extends DataFlowFunction, TaintFunction {
488481
StdOStreamOut() {
489-
this.getDeclaringType() instanceof StdBasicOStream and
490-
this.hasName(["operator<<", "put", "write"])
482+
this.getClassAndName(["operator<<", "put", "write"]) instanceof StdBasicOStream
491483
}
492484

493485
override predicate hasDataFlow(FunctionInput input, FunctionOutput output) {
@@ -602,10 +594,9 @@ private class StdBasicIOS extends ClassTemplateInstantiation {
602594
*/
603595
private class StdStreamFunction extends DataFlowFunction, TaintFunction {
604596
StdStreamFunction() {
605-
this.getDeclaringType() instanceof StdBasicIStream and
606-
this.hasName(["ignore", "unget", "seekg"])
597+
this.getClassAndName(["ignore", "unget", "seekg"]) instanceof StdBasicIStream
607598
or
608-
this.getDeclaringType() instanceof StdBasicOStream and this.hasName(["seekp", "flush"])
599+
this.getClassAndName(["seekp", "flush"]) instanceof StdBasicOStream
609600
or
610601
this.getClassAndName("copyfmt") instanceof StdBasicIOS
611602
}

0 commit comments

Comments
 (0)