Skip to content

Commit f744186

Browse files
myterondwiley258
authored andcommitted
some cosmetics
Signed-off-by: Helge Wehder <[email protected]> Signed-off-by: ewlxdnx <[email protected]>
1 parent 2825490 commit f744186

File tree

2 files changed

+8
-10
lines changed

2 files changed

+8
-10
lines changed

docs/Secure-Coding-Guide-for-Python/CWE-703/CWE-230/README.md

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ The `NaN` value should be stripped before as they can cause surprising or undefi
44
In python, some datasets use `NaN` (not-a-number) to represent the missing data. This can be problematic as the `NaN` values are unordered. Any ordered comparison of a number to a not-a-number value are `False`. A counter-intuitive implication is that `not-a-number` values are not equal to themselves.
55

66
This behavior is compliant with IEEE 754[[2024 Wikipedia]](https://en.wikipedia.org/wiki/IEEE_754) a hardware induced compromise.
7-
The [example01.py](example01.py) code demonstrates various comparisons of float('NaN') all resulting in False
7+
The [example01.py](example01.py) code demonstrates various comparisons of `float('NaN')` all resulting in `False`.
88

99
```python
1010
# SPDX-FileCopyrightText: OpenSSF project contributors
@@ -26,9 +26,7 @@ print(foo == float("NaN") or
2626

2727
## Non-Compliant Code Example
2828

29-
This noncompliant code example [[2024 docs.python.org]](https://docs.python.org/3/reference/expressions.html#value-comparisons) attempts a direct comparison with NaN in
30-
31-
_value == float("NaN").
29+
This noncompliant code example [[2024 docs.python.org]](https://docs.python.org/3/reference/expressions.html#value-comparisons) attempts a direct comparison with `NaN` in `_value == float("NaN")`.
3230

3331
*[noncompliant01.py](noncompliant01.py):*
3432

@@ -58,13 +56,13 @@ print(balance_is_positive("NaN"))
5856

5957
```
6058

61-
The balance_is_positive method returns True for all 3 cases instead of throwing an ValureError exception for balance_is_positive("NaN")
59+
The `balance_is_positive` method returns `True` for all 3 cases instead of throwing an `ValureError` exception for `balance_is_positive("NaN")`.
6260

6361
## Compliant Solution
6462

6563
In the `compliant01.py` code example, the method `Decimal.quantize` is used to gain control over known rounding errors in floating point values.
6664

67-
The decision by the `balance_is_positive` method is to `ROUND_DOWN` instead of the default `ROUND_HALF_EVEN`.
65+
The decision by the balance_is_positive method is to `ROUND_DOWN` instead of the default `ROUND_HALF_EVEN`.
6866

6967
*[compliant01.py](compliant01.py):*
7068

@@ -93,9 +91,9 @@ print(balance_is_positive("NaN"))
9391

9492
```
9593

96-
Decimal throws a decimal.InvalidOperation for NaN values, the controlled rounding causes only "0.01" to return True.
94+
`Decimal` throws a `decimal.InvalidOperation` for `NaN` values, the controlled rounding causes only `"0.01"` to return `True`.
9795

98-
In `compliant02.py` we use the `math.isnan` to verify if the value passed is a valid `float` value.
96+
In `compliant02.py` we use the math.isnan to very if the value passed is a valid `float` value.
9997

10098
*[compliant02.py](compliant02.py):*
10199

@@ -127,7 +125,7 @@ print(balance_is_positive("NaN"))
127125

128126
```
129127

130-
The balance_is_poitive method will raise an ValueError for NaN values.
128+
The `balance_is_poitive` method will raise an `ValueError` for `NaN` values.
131129

132130
## Automated Detection
133131

docs/Secure-Coding-Guide-for-Python/readme.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ It is __not production code__ and requires code-style or python best practices t
9292

9393
|[CWE-703: Improper Check or Handling of Exceptional Conditions](https://cwe.mitre.org/data/definitions/703.html)|Prominent CVE|
9494
|:----------------------------------------------------------------|:----|
95-
|[CWE-230: Improper Handling of Missing Values](CWE-703/CWE-230/.)||
95+
|[CWE-230: Improper Handling of Missing Values](CWE-703/CWE-230/README.md)||
9696
|[CWE-252: Unchecked Return Value](CWE-703/CWE-252/README.md)||
9797
|[CWE-390: Detection of Error Condition without Action](CWE-703/CWE-390/README.md)||
9898
|[CWE-392: Missing Report of Error Condition](CWE-703/CWE-392/README.md)||

0 commit comments

Comments
 (0)