Skip to content

Commit 4b5a203

Browse files
authored
Merge pull request #15463 from microsoft/42-false-positive-cpp-uninitializedlocal
False positive fix for cpp/uninitialized-local
2 parents a298a39 + 1a044fb commit 4b5a203

File tree

3 files changed

+19
-0
lines changed

3 files changed

+19
-0
lines changed

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,8 @@ VariableAccess commonException() {
5656
// Finally, exclude functions that contain assembly blocks. It's
5757
// anyone's guess what happens in those.
5858
containsInlineAssembly(result.getEnclosingFunction())
59+
or
60+
exists(Call c | c.getQualifier() = result | c.getTarget().isStatic())
5961
}
6062

6163
predicate isSinkImpl(Instruction sink, VariableAccess va) {
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
category: minorAnalysis
3+
---
4+
* The "Potentially uninitialized local variable" query (`cpp/uninitialized-local`) no longer reports an alert when the local variable is used as a qualifier to a static member function call.
5+
* ```

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)