Skip to content

Commit 64a87a8

Browse files
committed
C++: Remove uses of getQualifiedName
This removes all uses of `Declaration.getQualifiedName` that I think can be removed without changing any behaviour. The following uses in the LGTM default suite remain: * `cpp/ql/src/Security/CWE/CWE-121/UnterminatedVarargsCall.ql` (in `select`). * `cpp/ql/src/semmle/code/cpp/dataflow/internal/DataFlowDispatch.qll` (needs template args). * `cpp/ql/src/semmle/code/cpp/security/FunctionWithWrappers.qll` (used for alert messages).
1 parent 0a2e288 commit 64a87a8

File tree

16 files changed

+34
-61
lines changed

16 files changed

+34
-61
lines changed

cpp/ql/src/Critical/InitialisationNotRun.ql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ predicate global(GlobalVariable v) {
2020
}
2121

2222
predicate mainCalled(Function f) {
23-
f.getQualifiedName() = "main"
23+
f.hasGlobalName("main")
2424
or
2525
exists(Function caller | mainCalled(caller) and allCalls(caller, f))
2626
}

cpp/ql/src/Critical/SizeCheck.ql

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,12 @@ import cpp
1717
class Allocation extends FunctionCall {
1818
Allocation() {
1919
exists(string name |
20-
this.getTarget().hasQualifiedName(name) and
20+
this.getTarget().hasGlobalName(name) and
2121
(name = "malloc" or name = "calloc" or name = "realloc")
2222
)
2323
}
2424

25-
string getName() { result = this.getTarget().getQualifiedName() }
25+
private string getName() { this.getTarget().hasGlobalName(result) }
2626

2727
int getSize() {
2828
this.getName() = "malloc" and

cpp/ql/src/Critical/SizeCheck2.ql

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,12 @@ import cpp
1717
class Allocation extends FunctionCall {
1818
Allocation() {
1919
exists(string name |
20-
this.getTarget().hasQualifiedName(name) and
20+
this.getTarget().hasGlobalName(name) and
2121
(name = "malloc" or name = "calloc" or name = "realloc")
2222
)
2323
}
2424

25-
string getName() { result = this.getTarget().getQualifiedName() }
25+
private string getName() { this.getTarget().hasGlobalName(result) }
2626

2727
int getSize() {
2828
this.getName() = "malloc" and

cpp/ql/src/DefaultOptions.qll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ class Options extends string
6161
*/
6262
predicate exits(Function f) {
6363
f.getAnAttribute().hasName("noreturn") or
64-
exists(string name | f.getQualifiedName() = name |
64+
exists(string name | f.hasGlobalName(name) |
6565
name = "exit" or
6666
name = "_exit" or
6767
name = "abort" or

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,11 +58,11 @@ predicate refToStdString(Expr e, ConstructorCall source) {
5858
* will also become invalid.
5959
*/
6060
predicate flowFunction(Function fcn, int argIndex) {
61-
(fcn.getQualifiedName() = "_JNIEnv::NewStringUTF" and argIndex = 0)
61+
(fcn.hasQualifiedName("", "_JNIEnv", "NewStringUTF") and argIndex = 0)
6262
or
63-
(fcn.getQualifiedName() = "art::JNI::NewStringUTF" and argIndex = 1)
63+
(fcn.hasQualifiedName("art", "JNI", "NewStringUTF") and argIndex = 1)
6464
or
65-
(fcn.getQualifiedName() = "art::CheckJNI::NewStringUTF" and argIndex = 1)
65+
(fcn.hasQualifiedName("art", "CheckJNI", "NewStringUTF") and argIndex = 1)
6666

6767
// Add other functions that behave like NewStringUTF here.
6868
}

cpp/ql/src/Metrics/Files/FNumberOfTests.ql

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,10 @@ import cpp
1313

1414
Expr getTest() {
1515
// cppunit tests; https://freedesktop.org/wiki/Software/cppunit/
16-
exists(Function f | result.(FunctionCall).getTarget() = f
17-
and f.getNamespace().getName() = "CppUnit"
18-
and f.getName() = "addTest")
16+
result.(FunctionCall).getTarget().hasQualifiedName("CppUnit", _, "addTest")
1917
or
2018
// boost tests; http://www.boost.org/
21-
exists(Function f | result.(FunctionCall).getTarget() = f
22-
and f.getQualifiedName() = "boost::unit_test::make_test_case")
19+
result.(FunctionCall).getTarget().hasQualifiedName("boost::unit_test", "make_test_case")
2320
}
2421

2522
from File f, int n

cpp/ql/src/Security/CWE/CWE-022/TaintedPath.ql

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ import semmle.code.cpp.security.TaintTracking
2323
*/
2424
class FileFunction extends FunctionWithWrappers {
2525
FileFunction() {
26-
exists(string nme | this.getQualifiedName() = nme |
26+
exists(string nme | this.hasGlobalName(nme) |
2727
nme = "fopen" or
2828
nme = "_fopen" or
2929
nme = "_wfopen" or
@@ -32,10 +32,7 @@ class FileFunction extends FunctionWithWrappers {
3232
nme = "_wopen" or
3333

3434
// create file function on windows
35-
nme.matches("CreateFile%") or
36-
37-
// Objective C standard library
38-
nme.matches("NSFileHandle%::+fileHandleFor%AtPath:")
35+
nme.matches("CreateFile%")
3936
)
4037
or
4138
(

cpp/ql/src/Security/CWE/CWE-676/PotentiallyDangerousFunction.ql

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
import cpp
1313

1414
predicate potentiallyDangerousFunction(Function f, string message) {
15-
exists(string name | name = f.getQualifiedName() |
15+
exists(string name | f.hasGlobalName(name) |
1616
(
1717
name = "gmtime" or
1818
name = "localtime" or
@@ -21,7 +21,7 @@ predicate potentiallyDangerousFunction(Function f, string message) {
2121
) and
2222
message = "Call to " + name + " is potentially dangerous"
2323
) or (
24-
f.getQualifiedName() = "gets" and
24+
f.hasGlobalName("gets") and
2525
message = "gets does not guard against buffer overflow"
2626
)
2727
}

cpp/ql/src/jsf/4.10 Classes/AV Rule 79.ql

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ predicate acquireExpr(Expr acquire, string kind) {
2121
exists(FunctionCall fc, Function f, string name |
2222
fc = acquire and
2323
f = fc.getTarget() and
24-
name = f.getQualifiedName() and
24+
f.hasGlobalName(name) and
2525
(
2626
(
2727
name = "fopen" and
@@ -47,7 +47,7 @@ predicate releaseExpr(Expr release, Expr resource, string kind) {
4747
exists(FunctionCall fc, Function f, string name |
4848
fc = release and
4949
f = fc.getTarget() and
50-
name = f.getQualifiedName() and
50+
f.hasGlobalName(name) and
5151
(
5252
(
5353
name = "fclose" and
@@ -252,7 +252,7 @@ pragma[noopt] predicate badRelease(Resource r, Expr acquire, Function functionCa
252252
)
253253
}
254254

255-
Class qtObject() { result.getABaseClass*().getQualifiedName() = "QObject" }
255+
Class qtObject() { result.getABaseClass*().hasGlobalName("QObject") }
256256
PointerType qtObjectReference() { result.getBaseType() = qtObject() }
257257
Constructor qtParentConstructor() {
258258
exists(Parameter p |

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

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -74,20 +74,6 @@ class UserDefinedFormattingFunction extends FormattingFunction {
7474
override int getFormatParameterIndex() { callsVariadicFormatter(this, result) }
7575
}
7676

77-
/**
78-
* The Objective C method `stringWithFormat:`.
79-
*/
80-
class NsstringStringWithFormat extends FormattingFunction {
81-
NsstringStringWithFormat() {
82-
getQualifiedName().matches("NSString%::+stringWithFormat:") or
83-
getQualifiedName().matches("NSString%::+localizedStringWithFormat:")
84-
}
85-
86-
override int getFormatParameterIndex() {
87-
result = 0
88-
}
89-
}
90-
9177
/**
9278
* A call to one of the formatting functions.
9379
*/

0 commit comments

Comments
 (0)