![github-actions[bot]](/assets/img/avatar_default.png)
* Create rule S7412 * 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
707 B
Plaintext
25 lines
707 B
Plaintext
== Why is this an issue?
|
|
|
|
Performing operations like `offset` or `wrapping_add`/`wrapping_sub` on raw pointers to zero-sized types (ZSTs) results in no-op operations. This is likely unintended and could make the code misleading, potentially hiding bugs.
|
|
|
|
=== Code examples
|
|
|
|
==== Noncompliant code example
|
|
|
|
[source,rust,diff-id=1,diff-type=noncompliant]
|
|
----
|
|
unsafe { (&() as *const ()).offset(1); } // Noncompliant: No-op on zero-sized type pointer.
|
|
----
|
|
|
|
==== Compliant solution
|
|
|
|
[source,rust,diff-id=1,diff-type=compliant]
|
|
----
|
|
// Removing the no-op operation as it has no effect.
|
|
----
|
|
|
|
== Resources
|
|
=== Documentation
|
|
|
|
* Clippy Lints - https://rust-lang.github.io/rust-clippy/master/index.html#zst_offset
|