![github-actions[bot]](/assets/img/avatar_default.png)
* Create rule S7414 * Update RSPEC --------- Co-authored-by: yassin-kammoun-sonarsource <yassin-kammoun-sonarsource@users.noreply.github.com> Co-authored-by: yassin-kammoun-sonarsource <yassin.kammoun@sonarsource.com>
25 lines
688 B
Plaintext
25 lines
688 B
Plaintext
== Why is this an issue?
|
|
|
|
Using ``++core::intrinsics::transmute++`` in a way that is not valid on any architecture leads to undefined behavior. This can result in unpredictable program behavior or crashes.
|
|
|
|
=== Code examples
|
|
|
|
==== Noncompliant code example
|
|
|
|
[source,rust,diff-id=1,diff-type=noncompliant]
|
|
----
|
|
let ptr: *const T = core::intrinsics::transmute('x'); // Noncompliant: Invalid transmute operation.
|
|
----
|
|
|
|
==== Compliant solution
|
|
|
|
[source,rust,diff-id=1,diff-type=compliant]
|
|
----
|
|
let value: T = 'x' as T; // Compliant: Use a safe conversion method.
|
|
----
|
|
|
|
== Resources
|
|
=== Documentation
|
|
|
|
* Clippy Lints - https://rust-lang.github.io/rust-clippy/master/index.html#wrong_transmute
|