forked from github/codeql
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUnintendedDeclaration.cpp
More file actions
96 lines (73 loc) · 1.18 KB
/
UnintendedDeclaration.cpp
File metadata and controls
96 lines (73 loc) · 1.18 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
class Mutex
{
public:
Mutex();
~Mutex();
void lock();
void unlock();
private:
// ...
};
template<class T>
class Lock
{
public:
Lock() : m(0)
{
}
Lock(T &_m) : m(&_m)
{
m->lock();
}
~Lock()
{
if (m)
{
m->unlock();
}
}
private:
T *m;
};
Mutex myMutex;
void test1()
{
Lock<Mutex> myLock(myMutex); // GOOD (creates `myLock` on `myMutex`)
// ...
}
void test2()
{
Lock<Mutex> myLock(); // BAD (interpreted as a function declaration, this does nothing)
// ...
}
void test3()
{
Lock<Mutex> myLock; // GOOD (creates an uninitialized variable called `myLock`, probably intended)
// ...
}
void test4()
{
Lock<Mutex>(myMutex); // BAD (creates an uninitialized variable called `myMutex`, probably not intended)
// ...
}
void test5()
{
Lock<Mutex> myLock(Mutex); // BAD (interpreted as a function declaration, this does nothing)
// ...
}
class MyTestClass
{
public:
void test6()
{
Lock<Mutex> myLock(memberMutex); // GOOD (creates `myLock` on `memberMutex`)
// ...
}
void test7()
{
Lock<Mutex>(memberMutex); // BAD (creates an uninitialized variable called `memberMutex`, probably not intended) [NOT DETECTED]
// ...
}
private:
Mutex memberMutex;
};