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

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

There is a newer version: 10.2.0.105762
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 or assign numbers beyond those bounds, and the result will be a value that has silently wrapped around from the expected positive value to a negative one, or vice versa.

Noncompliant code example

public int Transform(int value)
{
    if (value <= 0)
    {
        return value;
    }
    int number = int.MaxValue;
    return number + value;  // Noncompliant
}

Compliant solution

public long Transform(int value)
{
    if (value <= 0)
    {
        return value;
    }
    long number = int.MaxValue;
    return number + value;
}

Resources

Standards





© 2015 - 2024 Weber Informatics LLC | Privacy Policy