Create rule S7414: Avoid transmutes that can never be correct (#4753)
* 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>
This commit is contained in:
parent
87a178f05b
commit
ea0dd90530
2
rules/S7414/metadata.json
Normal file
2
rules/S7414/metadata.json
Normal file
@ -0,0 +1,2 @@
|
||||
{
|
||||
}
|
24
rules/S7414/rust/metadata.json
Normal file
24
rules/S7414/rust/metadata.json
Normal file
@ -0,0 +1,24 @@
|
||||
{
|
||||
"title": "Avoid transmutes that can never be correct",
|
||||
"type": "BUG",
|
||||
"status": "ready",
|
||||
"remediation": {
|
||||
"func": "Constant\/Issue",
|
||||
"constantCost": "5min"
|
||||
},
|
||||
"tags": [
|
||||
"clippy"
|
||||
],
|
||||
"defaultSeverity": "Major",
|
||||
"ruleSpecification": "RSPEC-7414",
|
||||
"sqKey": "S7414",
|
||||
"scope": "All",
|
||||
"defaultQualityProfiles": ["Sonar way"],
|
||||
"quickfix": "unknown",
|
||||
"code": {
|
||||
"impacts": {
|
||||
"RELIABILITY": "HIGH"
|
||||
},
|
||||
"attribute": "LOGICAL"
|
||||
}
|
||||
}
|
24
rules/S7414/rust/rule.adoc
Normal file
24
rules/S7414/rust/rule.adoc
Normal file
@ -0,0 +1,24 @@
|
||||
== 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
|
Loading…
x
Reference in New Issue
Block a user