rspec/rules/S3949/csharp/rule.adoc
Fred Tingaud 6f24cc0632
Clean rule at root
In some cases, the `rule.adoc` at root of a rule is never included
anywhere and thus is dead code.
It's a maintenance cost by itself, but also it misses opportunities to
inline code that seems used by two documents when in fact only one
document is actually rendered. And this missed opportunity, in turn,
stops us from applying the correct language tag on the code samples.
2023-10-16 16:34:38 +02:00

37 lines
777 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;
}
----
include::../rspecator.adoc[]