
* Update JSON schema to include STIG ASD 2023-06-08 mapping * Update rules to add STIG metadata mappings --------- Co-authored-by: Loris Sierra <loris.sierra@sonarsource.com>
34 lines
974 B
Plaintext
34 lines
974 B
Plaintext
== Why is this an issue?
|
|
|
|
Numbers are infinite, but the types that hold them are not. Each numeric type has hard upper and lower bounds. Try to calculate numbers beyond those bounds, and the result will be an `OverflowException`. When the compilation is configured to remove integer overflow checking, the value will be silently wrapped around from the expected positive value to a negative one, or vice versa.
|
|
|
|
== Noncompliant code example
|
|
|
|
[source,vbnet]
|
|
----
|
|
Public Function Transform(Value As Integer) As Integer
|
|
If Value <= 0 Then Return Value
|
|
Dim Number As Integer = Integer.MaxValue
|
|
Return Number + Value ' Noncompliant
|
|
End Function
|
|
----
|
|
|
|
== Compliant solution
|
|
|
|
[source,vbnet]
|
|
----
|
|
Public Function Transform(Value As Integer) As Long
|
|
If Value <= 0 Then Return Value
|
|
Dim Number As Long = Integer.MaxValue
|
|
Return Number + Value
|
|
End Function
|
|
----
|
|
|
|
|
|
== Resources
|
|
|
|
include::../common/resources/standards.adoc[]
|
|
|
|
|
|
include::../rspecator.adoc[]
|