Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit33bc0b1

Browse files
Merge pull request#973 from github/michaelrfairhurst/fix-972-lock-guard-doesnt-require-catch-in-CON51-cpp
Fix#972, CON51-CPP falsely reporting that std::lock_guard requires catch
2 parentsa612c2c +59785c5 commit33bc0b1

File tree

5 files changed

+36
-4
lines changed

5 files changed

+36
-4
lines changed
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
-`CON51-CPP` -`EnsureActivelyHeldLocksAreReleasedOnExceptionalConditions.ql`:
2+
- Exclude RAII-style locks from query results, as they cannot be leaked, and are recommended to avoid alerts in this rule.

‎cpp/cert/src/rules/CON51-CPP/EnsureActivelyHeldLocksAreReleasedOnExceptionalConditions.ql‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@ where
3636
// To reduce the number of results we require that this is a direct child
3737
// of the lock within the same function
3838
lpn.coveredByLock().getASuccessor*()=lpnand
39+
// Exclude RAII-style locks which cannot leak
40+
lpn.coveredByLock().canLeak()and
3941
// report those expressions for which there doesn't exist a catch block
4042
notexists(CatchBlockcb|
4143
catches(cb,lpn, _)and

‎cpp/cert/test/rules/CON51-CPP/test.cpp‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,11 @@ void f8(std::mutex *pm) {
8383
}
8484
}
8585

86+
voidf9(std::mutex *pm) {
87+
std::lock_guard<std::mutex>lg(*pm);
88+
mightThrow();// COMPLIANT
89+
}
90+
8691
voidm() {
8792
std::mutex pm;
8893
std::thread t1 =std::thread(f1, &pm);
@@ -93,4 +98,5 @@ void m() {
9398
std::thread t6 =std::thread(f6, &pm);
9499
std::thread t7 =std::thread(f7, &pm);
95100
std::thread t8 =std::thread(f8, &pm);
101+
std::thread t9 =std::thread(f9, &pm);
96102
}

‎cpp/common/src/codingstandards/cpp/concurrency/LockProtectedControlFlow.qll‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,10 @@ class LockProtectedControlFlowNode extends ThreadedCFN {
3838
}
3939

4040
/**
41-
* The `MutexFunctionCall` holding the lock that locks this node.
41+
* The LockingOperation (for instance, a `MutexFunctionCall`, or RAII-style lock constructor)
42+
* holding the lock that locks this node.
4243
*/
43-
FunctionCallcoveredByLock(){result=lockingFunction}
44+
LockingOperationcoveredByLock(){result=lockingFunction}
4445

4546
/**
4647
* The lock underlying this `LockProtectedControlFlowNode`.

‎cpp/common/src/codingstandards/cpp/concurrency/LockingOperation.qll‎

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,11 @@ abstract class LockingOperation extends FunctionCall {
2222
*/
2323
abstractpredicateisUnlock();
2424

25+
/**
26+
* Holds if this locking operation can leak the lock. For example, RAII-style locks cannot leak.
27+
*/
28+
abstractpredicatecanLeak();
29+
2530
/**
2631
* Holds if this locking operation is really a locking operation within a
2732
* designated locking operation. This library assumes the underlying locking
@@ -33,11 +38,27 @@ abstract class LockingOperation extends FunctionCall {
3338
}
3439
}
3540

41+
/**
42+
* A locking operation that can leak the lock.
43+
*
44+
* RAII style locks cannot leak, but other kinds of locks can.
45+
*/
46+
abstractclassLeakableLockingOperationextendsLockingOperation{
47+
overridepredicatecanLeak(){any()}
48+
}
49+
50+
/**
51+
* A locking operation that cannot leak the lock, such as RAII-style locks.
52+
*/
53+
abstractclassNonLeakableLockingOperationextendsLockingOperation{
54+
overridepredicatecanLeak(){none()}
55+
}
56+
3657
/**
3758
* Common base class providing an interface into function call
3859
* based mutex locks.
3960
*/
40-
abstractclassMutexFunctionCallextendsLockingOperation{
61+
abstractclassMutexFunctionCallextendsLeakableLockingOperation{
4162
abstractpredicateisRecursive();
4263

4364
abstractpredicateisSpeculativeLock();
@@ -180,7 +201,7 @@ class CMutexFunctionCall extends MutexFunctionCall {
180201
/**
181202
* Models a RAII-Style lock.
182203
*/
183-
classRAIIStyleLockextendsLockingOperation{
204+
classRAIIStyleLockextendsNonLeakableLockingOperation{
184205
VariableAccesslock;
185206

186207
RAIIStyleLock(){

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp