mirror of
https://github.com/github/codeql.git
synced 2026-05-03 04:39:29 +02:00
Merge pull request #5570 from geoffw0/mutextest
C++: Add mutex test cases.
This commit is contained in:
@@ -7,3 +7,4 @@
|
||||
| test.cpp:303:11:303:18 | call to try_lock | This lock might not be unlocked or might be locked more times than it is unlocked. |
|
||||
| test.cpp:313:11:313:18 | call to try_lock | This lock might not be unlocked or might be locked more times than it is unlocked. |
|
||||
| test.cpp:442:8:442:17 | call to mutex_lock | This lock might not be unlocked or might be locked more times than it is unlocked. |
|
||||
| test.cpp:482:2:482:19 | call to pthread_mutex_lock | This lock might not be unlocked or might be locked more times than it is unlocked. |
|
||||
|
||||
@@ -445,3 +445,46 @@ bool test_mutex(data_t *data)
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
// ---
|
||||
|
||||
struct pthread_mutex
|
||||
{
|
||||
// ...
|
||||
};
|
||||
|
||||
void pthread_mutex_lock(pthread_mutex *m);
|
||||
void pthread_mutex_unlock(pthread_mutex *m);
|
||||
|
||||
class MyClass
|
||||
{
|
||||
public:
|
||||
pthread_mutex lock;
|
||||
};
|
||||
|
||||
bool maybe();
|
||||
|
||||
int test_MyClass_good(MyClass *obj)
|
||||
{
|
||||
pthread_mutex_lock(&obj->lock);
|
||||
|
||||
if (maybe()) {
|
||||
pthread_mutex_unlock(&obj->lock);
|
||||
return -1; // GOOD
|
||||
}
|
||||
|
||||
pthread_mutex_unlock(&obj->lock); // GOOD
|
||||
return 0;
|
||||
}
|
||||
|
||||
int test_MyClass_bad(MyClass *obj)
|
||||
{
|
||||
pthread_mutex_lock(&obj->lock);
|
||||
|
||||
if (maybe()) {
|
||||
return -1; // BAD
|
||||
}
|
||||
|
||||
pthread_mutex_unlock(&obj->lock); // GOOD
|
||||
return 0;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user