Skip to content

Commit 4a7f910

Browse files
committed
C++: Respond to review comments.
1 parent 10a9f7b commit 4a7f910

File tree

2 files changed

+6
-9
lines changed

2 files changed

+6
-9
lines changed

cpp/ql/src/Likely Bugs/OO/UnsafeUseOfThis.qhelp

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,11 @@
55

66

77
<overview>
8-
<p>This rule finds calls to pure virtual member functions in constructors and destructors. Such calls do not perform virtual dispatch, and can cause undefined behavior.</p>
8+
<p>This rule finds calls to pure virtual member functions in constructors and destructors. When executing the body of a constructor of class <code>T</code>, the virtual table of <code>T</code> refers to the virtual table of one of <code>T</code>'s base classes. This can produce unexpected behavior, including program abort that can lead to denial of service attacks. The same problem exists during destruction of an object.</p>
99

1010
</overview>
1111
<recommendation>
12-
<p>Do not rely on virtual dispatch in constructors and destructors. Instead, each class should be responsible for acquiring and releasing its resources.</p>
12+
<p>Do not rely on virtual dispatch in constructors and destructors. Instead, each class should be responsible for acquiring and releasing its resources. If a base class needs to refer to a derived class during initialization, use the Dynamic Binding During Initialization idiom.</p>
1313

1414
</recommendation>
1515
<example><sample src="UnsafeUseOfThis.cpp" />
@@ -19,14 +19,11 @@
1919
</example>
2020
<references>
2121

22-
<li>
23-
<a href="https://isocpp.org/wiki/faq/strange-inheritance#calling-virtuals-from-ctors">When my base class’s constructor calls a virtual function on its this object, why doesn’t my derived class’s override of that virtual function get invoked?</a>
22+
<li>ISO C++ FAQ: <a href="https://isocpp.org/wiki/faq/strange-inheritance#calling-virtuals-from-ctors">When my base class's constructor calls a virtual function on its this object, why doesn't my derived class's override of that virtual function get invoked?</a>
2423
</li>
25-
<li>
26-
<a href="https://wiki.sei.cmu.edu/confluence/display/cplusplus/OOP50-CPP.+Do+not+invoke+virtual+functions+from+constructors+or+destructors">OOP50-CPP. Do not invoke virtual functions from constructors or destructors</a>
24+
<li>SEI CERT C++ Coding Standard <a href="https://wiki.sei.cmu.edu/confluence/display/cplusplus/OOP50-CPP.+Do+not+invoke+virtual+functions+from+constructors+or+destructors">OOP50-CPP. Do not invoke virtual functions from constructors or destructors</a>
2725
</li>
28-
<li>
29-
<a href="https://scc.ustc.edu.cn/zlsc/sugon/intel/ssadiag_docs/pt_reference/references/sc_cpp_virtual_call_in_ctor.htm">Virtual function call in constructor</a>
26+
<li>ISO C++ FAQ: <a href="https://isocpp.org/wiki/faq/strange-inheritance#calling-virtuals-from-ctor-idiom">Okay, but is there a way to simulate that behavior as if dynamic binding worked on the this object within my base class's constructor?</a>
3027
</li>
3128

3229

cpp/ql/src/Likely Bugs/OO/UnsafeUseOfThis.ql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/**
22
* @name Unsafe use of this in constructor
3-
* @description A call to a pure virtual function using a this
3+
* @description A call to a pure virtual function using a 'this'
44
* pointer of an object that is under construction
55
* may lead to undefined behavior.
66
* @kind path-problem

0 commit comments

Comments
 (0)