All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.sonar.plugins.vbnet.S3949.html Maven / Gradle / Ivy

There is a newer version: 10.5.0.109200
Show newest version

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

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

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

Standards





© 2015 - 2025 Weber Informatics LLC | Privacy Policy