Skip to content

Commit 13cf555

Browse files
committed
False positive fix for cpp/uninitialized-local
1 parent aeae208 commit 13cf555

File tree

3 files changed

+22
-1
lines changed

3 files changed

+22
-1
lines changed

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,5 +86,10 @@ from
8686
where
8787
conf.hasFlowPath(source, sink) and
8888
isSinkImpl(sink.getInstruction(), va) and
89-
v = va.getTarget()
89+
v = va.getTarget() and
90+
(
91+
exists(Call c | c.getQualifier() = va)
92+
implies
93+
exists(Call c | c.getQualifier() = va and not c.getTarget().isStatic())
94+
)
9095
select va, "The variable $@ may not be initialized at this access.", v, v.getName()
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
---
2+
category: minorAnalysis
3+
---
4+
* Corrected a false positive with `cpp/uninitialized-local`: `a->func()` is a false positive if `func` is static regardless of if `a` is initializeed.

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -532,4 +532,16 @@ int non_exhaustive_switch_2(State s) {
532532
return y; // GOOD (y is not initialized when s = StateC, but if s = StateC we won't reach this point)
533533
}
534534
return 0;
535+
}
536+
537+
class StaticMethodClass{
538+
public:
539+
static int get(){
540+
return 1;
541+
}
542+
};
543+
544+
int static_method_false_positive(){
545+
StaticMethodClass *t;
546+
int i = t->get(); // GOOD: the `get` method is static and this is equivalent to StaticMethodClass::get()
535547
}

0 commit comments

Comments
 (0)