
Inline adoc files when they are included exactly once. Also fix language tags because this inlining gives us better information on what language the code is written in.
60 lines
1.1 KiB
Plaintext
60 lines
1.1 KiB
Plaintext
If the denominator to a division or modulo operation is zero it would result in a fatal error.
|
|
|
|
== Why is this an issue?
|
|
|
|
This is an issue because dividing by zero is a forbidden operation which leads to a fatal error.
|
|
|
|
=== What is the potential impact?
|
|
|
|
This issue can lead your program to an unexpected halt with all the inconveniences it entails.
|
|
|
|
== How to fix it
|
|
|
|
Make sure that zero never reaches the denominator.
|
|
|
|
=== Code examples
|
|
|
|
==== Noncompliant code example
|
|
|
|
[source,python,diff-id=1,diff-type=noncompliant]
|
|
----
|
|
def non_compliant():
|
|
z = 0
|
|
if (unknown()):
|
|
# ...
|
|
z = 4
|
|
else:
|
|
# ...
|
|
z = 1 / z
|
|
----
|
|
|
|
==== Compliant solution
|
|
|
|
[source,python,diff-id=1,diff-type=compliant]
|
|
----
|
|
def compliant():
|
|
z = 0
|
|
if (unknown()):
|
|
# ...
|
|
z = 4
|
|
else:
|
|
# ...
|
|
z = 1
|
|
z = 1 / z
|
|
----
|
|
|
|
=== How does this work?
|
|
|
|
By ensuring that for all the paths that can define the variable ++z++, when none assigns it zero, we are sure that the issue is fixed.
|
|
|
|
//=== Pitfalls
|
|
|
|
//=== Going the extra mile
|
|
|
|
|
|
//== Resources
|
|
//=== Documentation
|
|
//=== Articles & blog posts
|
|
//=== Conference presentations
|
|
//=== Standards
|