mirror of
https://github.com/github/codeql.git
synced 2026-04-28 02:05:14 +02:00
C++: Demonstrate false positives when a const variable is initialized in a parameter list
This commit is contained in:
@@ -0,0 +1,29 @@
|
||||
void func_with_default_arg(const int n = 0) {
|
||||
if(n <= 10) {} // GOOD [FALSE POSITIVE]
|
||||
}
|
||||
|
||||
struct A {
|
||||
const int int_member = 0;
|
||||
A(int n) : int_member(n) {
|
||||
if(int_member <= 10) {
|
||||
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
struct B {
|
||||
B(const int n = 0) {
|
||||
if(n <= 10) {} // GOOD [FALSE POSITIVE]
|
||||
}
|
||||
};
|
||||
|
||||
const volatile int volatile_const_global = 0;
|
||||
|
||||
void test1() {
|
||||
func_with_default_arg(100);
|
||||
|
||||
A a(100);
|
||||
if(a.int_member <= 10) {}
|
||||
|
||||
if(volatile_const_global <= 10) {} // GOOD [FALSE POSITIVE]
|
||||
}
|
||||
@@ -38,5 +38,8 @@
|
||||
| PointlessComparison.c:303:9:303:14 | ... >= ... | Comparison is always false because c <= 0. |
|
||||
| PointlessComparison.c:312:9:312:14 | ... >= ... | Comparison is always false because c <= 0. |
|
||||
| PointlessComparison.c:337:14:337:21 | ... >= ... | Comparison is always true because x >= 0. |
|
||||
| PointlessComparison.cpp:2:8:2:14 | ... <= ... | Comparison is always true because n <= 0. |
|
||||
| PointlessComparison.cpp:16:12:16:18 | ... <= ... | Comparison is always true because n <= 0. |
|
||||
| PointlessComparison.cpp:28:8:28:34 | ... <= ... | Comparison is always true because volatile_const_global <= 0. |
|
||||
| RegressionTests.cpp:57:7:57:22 | ... <= ... | Comparison is always true because * ... <= 4294967295. |
|
||||
| Templates.cpp:9:10:9:24 | ... <= ... | Comparison is always true because local <= 32767. |
|
||||
|
||||
Reference in New Issue
Block a user