File tree Expand file tree Collapse file tree 1 file changed +8
-7
lines changed
src/coding-guidelines/types-and-traits Expand file tree Collapse file tree 1 file changed +8
-7
lines changed Original file line number Diff line number Diff line change 5151 :id: non_compl_ex_UnionBool
5252 :status: draft
5353
54- This noncompliant example reads a Boolean from a union field containing an invalid bit pattern .
55- The value ``3`` is not a valid Boolean (only ``0`` and ``1`` are valid).
54+ This noncompliant example reads an invalid bit pattern from a Boolean union field.
55+ The value ``3`` is not a valid value of type ``bool`` (only ``0`` and ``1`` are valid).
5656
5757 .. code-block:: rust
5858
7272 :id: non_compl_ex_UnionChar
7373 :status: draft
7474
75- This noncompliant example reads a ``char`` from a ``union`` containing an invalid Unicode value .
75+ This noncompliant example reads an invalid Unicode value from a ``union`` field of type ``char`` .
7676
7777 .. code-block:: rust
7878
121121 :id: non_compl_ex_UnionRef
122122 :status: draft
123123
124- This noncompliant example reads a reference from a ``union`` containing a null or misaligned pointer.
124+ This noncompliant example reads a reference from a ``union`` containing a null pointer.
125+ A similar problem occurs when reading a misaligned pointer.
125126
126127 .. code-block:: rust
127128
133134 fn main () {
134135 let u = PtrOrRef { p: std::ptr::null () };
135136
136- // Non-compliant: null is not a valid reference
137- let invalid_ref = unsafe { u.r }; // UB: references cannot be null
137+ // Undefined behavior reading a null value from a reference field of a union
138+ unsafe { u.r }; // Noncompliant
138139 }
139140
140141 .. compliant_example::
196197 :id: compl_ex_UnionSameField
197198 :status: draft
198199
199- This compliant solution read from the same field that was written.
200+ This compliant solution reads from the same field that was written.
200201
201202 .. code-block:: rust
202203
You can’t perform that action at this time.
0 commit comments