
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.
45 lines
889 B
Plaintext
45 lines
889 B
Plaintext
== Why is this an issue?
|
|
|
|
include::../description.adoc[]
|
|
|
|
=== Noncompliant code example
|
|
|
|
[source,java]
|
|
----
|
|
public boolean isOdd(int x) {
|
|
return x % 2 == 1; // Noncompliant; if x is an odd negative, x % 2 == -1
|
|
}
|
|
----
|
|
|
|
|
|
=== Compliant solution
|
|
|
|
[source,java]
|
|
----
|
|
public boolean isOdd(int x) {
|
|
return x % 2 != 0;
|
|
}
|
|
----
|
|
|
|
|
|
== Resources
|
|
|
|
* https://wiki.sei.cmu.edu/confluence/x/pDdGBQ[CERT, NUM51-J.] - Do not assume that the remainder operator always returns a nonnegative result for integral operands
|
|
* https://wiki.sei.cmu.edu/confluence/x/_NUxBQ[CERT, INT10-C] - Do not assume a positive remainder when using the % operator
|
|
|
|
ifdef::env-github,rspecator-view[]
|
|
|
|
'''
|
|
== Implementation Specification
|
|
(visible only on this page)
|
|
|
|
include::../message.adoc[]
|
|
|
|
'''
|
|
== Comments And Links
|
|
(visible only on this page)
|
|
|
|
include::../comments-and-links.adoc[]
|
|
|
|
endif::env-github,rspecator-view[]
|