25 lines
674 B
Plaintext
25 lines
674 B
Plaintext
![]() |
== Why is this an issue?
|
||
|
|
||
|
Transmuting a null pointer is undefined behavior and can lead to unpredictable program crashes and security vulnerabilities.
|
||
|
|
||
|
=== Code examples
|
||
|
|
||
|
==== Noncompliant code example
|
||
|
|
||
|
[source,rust,diff-id=1,diff-type=noncompliant]
|
||
|
----
|
||
|
let null_ref: &u64 = unsafe { std::mem::transmute(0 as *const u64) }; // Noncompliant: Transmuting a null pointer.
|
||
|
----
|
||
|
|
||
|
==== Compliant solution
|
||
|
|
||
|
[source,rust,diff-id=1,diff-type=compliant]
|
||
|
----
|
||
|
let null_ref: Option<&u64> = None; // Compliant: Use Option to represent nullable references.
|
||
|
----
|
||
|
|
||
|
== Resources
|
||
|
=== Documentation
|
||
|
|
||
|
* Clippy Lints - https://rust-lang.github.io/rust-clippy/master/index.html#transmuting_null
|