CPP: Add a test of common mistakes using locking classes.#1204
CPP: Add a test of common mistakes using locking classes.#1204jbj merged 2 commits intogithub:masterfrom
Conversation
|
|
||
| ~Lock() | ||
| { | ||
| m->unlock(); |
There was a problem hiding this comment.
If you guard this in if (m), then none of the bad examples below will segfault. That makes it a much more scary bug.
|
So as I see it there are two issues: (1) AV Rule 107.ql ('Function declared in block') is only a (the other relevant query, LocalVariableHidesGlobalVariable.ql, is a (2) [As far as I'm aware] the result in 'test7' is not flagged by any query. |
|
(2) could take the form of a LocalVariableHidesMemberVariable.ql query (which you warned might be noisy, but I don't yet follow why) or a 'generalised "expression has no effect"' as you described in the older discussion (which I suspect might work out quite complicated, but could potentially spot more problems). |
|
Noisy or not, How about giving an alert when
I think Bug |
(follows on from discussion with @jbj on #1192)
Add a test showing a couple of common locking pitfalls, which we want to ensure we have good test coverage for:
#6in Curiously Recurring C++ Bugs at Facebook, where a variable is declared for the lock but a difficult to spot typo results in the default constructor being called rather than the intended oneNote that
AV Rule 107has been downgraded to a recommendation.