Skip to content

Commit c246a5d

Browse files
committed
Fix potential errors in Ime::ComPtr and Ime::ComQIPtr smart pointers.
1 parent 95351bf commit c246a5d

File tree

1 file changed

+13
-9
lines changed

1 file changed

+13
-9
lines changed

ComPtr.h

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -36,17 +36,19 @@ class ComPtr {
3636
}
3737

3838
ComPtr(T* p, bool ref = true): p_(p) {
39-
if(p_ && ref)
39+
if (p_ && ref) {
4040
p_->AddRef();
41+
}
4142
}
4243

43-
ComPtr(ComPtr&& other) : p_(other.p_) {
44+
ComPtr(ComPtr&& other) noexcept : p_(other.p_) {
4445
other.p_ = nullptr;
4546
}
4647

4748
ComPtr(const ComPtr& other): p_(other.p_) {
48-
if(p_)
49+
if (p_) {
4950
p_->AddRef();
51+
}
5052
}
5153

5254
~ComPtr(void) {
@@ -87,7 +89,7 @@ class ComPtr {
8789
return p_ < p;
8890
}
8991

90-
ComPtr& operator = (ComPtr&& other) {
92+
ComPtr& operator = (ComPtr&& other) noexcept {
9193
p_ = other.p_;
9294
other.p_ = nullptr;
9395
return *this;
@@ -100,10 +102,12 @@ class ComPtr {
100102
ComPtr& operator = (T* p) {
101103
T* old = p_;
102104
p_ = p;
103-
if(p_)
105+
if (p_) {
104106
p_->AddRef();
105-
if (old)
107+
}
108+
if (old) {
106109
old->Release();
110+
}
107111
return *this;
108112
}
109113

@@ -130,17 +134,17 @@ class ComQIPtr: public ComPtr<T> {
130134
ComQIPtr(const ComQIPtr& other): ComPtr<T>(other) {
131135
}
132136

133-
ComQIPtr(ComQIPtr&& other) : ComPtr<T>(std::move(other)) {
137+
ComQIPtr(ComQIPtr&& other) noexcept : ComPtr<T>(std::move(other)) {
134138
}
135139

136-
ComQIPtr(IUnknown* p) {
140+
ComQIPtr(IUnknown* p) : ComPtr<T>() {
137141
if(p) {
138142
p->QueryInterface(__uuidof(T), (void**)&p_);
139143
}
140144
}
141145

142146
ComQIPtr& operator = (IUnknown* p) {
143-
ComPtr<T>::operator = (NULL);
147+
ComPtr<T>::operator = (nullptr);
144148
if(p) {
145149
p->QueryInterface(__uuidof(T), (void**)&p_);
146150
}

0 commit comments

Comments
 (0)