Skip to content

Commit b876117

Browse files
committed
C++: Add more QLDoc.
1 parent 01fc743 commit b876117

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

cpp/ql/src/Security/CWE/CWE-843/TypeConfusion.ql

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,20 @@ class UnsafeCast extends Cast {
139139

140140
Class getConvertedType() { result = toType }
141141

142+
/**
143+
* Holds if the result of this cast can safely be interpreted as a value of
144+
* type `t`.
145+
*
146+
* The compatibility rules are as follows:
147+
*
148+
* 1. the result of `(T)x` is compatible with the type `T` for any `T`
149+
* 2. the result of `(T)x` is compatible with the type `U` for any `U` such
150+
* that `U` is a subtype of `T`, or `T` is a subtype of `U`.
151+
* 3. the result of `(T)x` is compatible with the type `U` if `U` the list
152+
* of fields of `U` is a prefix of the list of fields of `T`.
153+
* For example, if `T` is `struct { unsigned char x; int y; };`
154+
* and `U` is `struct { unsigned char uc; };`.
155+
*/
142156
bindingset[this, t]
143157
pragma[inline_late]
144158
predicate compatibleWith(Type t) {

0 commit comments

Comments
 (0)