rspec/rules/S3949/csharp/rule.adoc
Jamie Anderson 9ee16daa47
Modify rules: Add STIG AS&D 2023-06-08 mappings (#3914)
* 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>
2024-05-06 08:56:31 +02:00

43 lines
840 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 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
[source,csharp]
----
public int Transform(int value)
{
if (value <= 0)
{
return value;
}
int number = int.MaxValue;
return number + value; // Noncompliant
}
----
== Compliant solution
[source,csharp]
----
public long Transform(int value)
{
if (value <= 0)
{
return value;
}
long number = int.MaxValue;
return number + value;
}
----
== Resources
include::../common/resources/standards.adoc[]
include::../rspecator.adoc[]