Skip to content

Commit 1a0d66b

Browse files
authored
Merge pull request github#16557 from MathiasVP/fix-unique-pointer-query-fp
C++: Fix `cpp/use-of-unique-pointer-after-lifetime-ends` FP
2 parents bbebdfe + 9907f0f commit 1a0d66b

File tree

3 files changed

+14
-0
lines changed

3 files changed

+14
-0
lines changed

cpp/ql/src/Security/CWE/CWE-416/UseOfUniquePointerAfterLifetimeEnds.ql

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ where
3030
outlivesFullExpr(c) and
3131
not c.isFromUninstantiatedTemplate(_) and
3232
isUniquePointerDerefFunction(c.getTarget()) and
33+
// Exclude cases where the pointer is implicitly converted to a non-pointer type
34+
not c.getActualType() instanceof IntegralType and
3335
isTemporary(c.getQualifier().getFullyConverted())
3436
select c,
3537
"The underlying unique pointer object is destroyed after the call to '" + c.getTarget() +
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
---
2+
category: minorAnalysis
3+
---
4+
* The "Use of unique pointer after lifetime ends" query (`cpp/use-of-unique-pointer-after-lifetime-ends`) no longer reports an alert when the pointer is converted to a boolean

cpp/ql/test/query-tests/Security/CWE/CWE-416/semmle/tests/UseOfUniquePtrAfterLifetimeEnds/test.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,4 +203,12 @@ void test2(bool b1, bool b2) {
203203
auto s11 = b2 ? nullptr : sRefRef.get(); // GOOD
204204
const S* s12;
205205
s12 = sRefRef.get(); // GOOD
206+
}
207+
208+
void test_convert_to_bool() {
209+
bool b = get_unique_ptr().get(); // GOOD
210+
211+
if(get_unique_ptr().get()) { // GOOD
212+
213+
}
206214
}

0 commit comments

Comments
 (0)