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

Skip to content

Commit fa43ae2

Browse files
author
Robert Marsh
authored
Merge pull request #1615 from geoffw0/exprowninit
CPP: Test + workaround for UseInOwnInitializer.ql
2 parents 137427f + 85707cf commit fa43ae2

3 files changed

Lines changed: 25 additions & 0 deletions

File tree

change-notes/1.22/analysis-cpp.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
| No space for zero terminator (`cpp/no-space-for-terminator`) | Fewer false positive results | False positives involving strings that are not null-terminated have been excluded. |
1818
| Suspicious pointer scaling (`cpp/suspicious-pointer-scaling`) | Lower precision | The precision of this query has been reduced to "medium". This coding pattern is used intentionally and safely in a number of real-world projects. Results are no longer displayed on LGTM unless you choose to display them. |
1919
| Non-constant format string (`cpp/non-constant-format`) | Fewer false positive results | Rewritten using the taint-tracking library. |
20+
| Variable used in its own initializer (`cpp/use-in-own-initializer`) | Fewer false positive results | False positives for constant variables with the same name in different namespaces have been removed. |
2021

2122
## Changes to QL libraries
2223

cpp/ql/src/Likely Bugs/UseInOwnInitializer.ql

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ where va.initializesItself(v, init)
3232
exists (CrementOperation crement | crement.getAnOperand() = va)
3333
)
3434
and not va.isUnevaluated()
35+
and not v.isConst()
3536
and not (
3637
va.getParent() = init and
3738
exists(MacroInvocation mi |

cpp/ql/test/query-tests/Likely Bugs/UseInOwnInitializer/test.cpp

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,3 +66,26 @@ void test11() {
6666
void test12() {
6767
self_initialize(int, x); // GOOD (statement is from a macro)
6868
}
69+
70+
namespace ns1
71+
{
72+
const int v2 = 1;
73+
const int v4 = 1;
74+
const int v6 = 1;
75+
};
76+
77+
namespace ns2
78+
{
79+
const int v1 = ns1::v2; // GOOD
80+
const int v2 = ns1::v2; // GOOD [produces INVALID_KEY trap warning]
81+
};
82+
83+
const int v3 = ns1::v4; // GOOD
84+
const int v4 = ns1::v4; // GOOD
85+
86+
namespace ns3
87+
{
88+
const int v5 = ns1::v6 + 1; // GOOD
89+
const int v6 = ns1::v6 + 1; // GOOD [produces INVALID_KEY trap warning]
90+
const int v7 = ns3::v7; // BAD [NOT DETECTED]
91+
};

0 commit comments

Comments
 (0)