You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/Secure-Coding-Guide-for-Python/CWE-703/CWE-230/README.md
+19-15Lines changed: 19 additions & 15 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -4,13 +4,14 @@ In python, some datasets use NaN (not-a-number) to represent the missing data. T
4
4
5
5
This behavior is compliant with IEEE 754[[2024 Wikipedia]](https://en.wikipedia.org/wiki/IEEE_754) a hardware induced compromise.
6
6
The [example01.py](example01.py) code demonstrates various comparisons of float('NaN') all resulting in False
7
+
7
8
```python
8
9
""" Code Example """
9
-
10
+
10
11
foo =float('NaN')
11
12
print(f"foo={foo} type = {type(foo)}")
12
-
13
-
13
+
14
+
14
15
print(foo ==float("NaN") or
15
16
foo isfloat("NaN") or
16
17
foo <3or
@@ -19,6 +20,7 @@ print(foo == float("NaN") or
19
20
)
20
21
21
22
```
23
+
22
24
## Non-Compliant Code Example
23
25
24
26
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
@@ -29,8 +31,8 @@ _value == float("NaN").
29
31
30
32
```python
31
33
""" Non-compliant Code Example """
32
-
33
-
34
+
35
+
34
36
defbalance_is_positive(value: str) -> bool:
35
37
"""Returns True if there is still enough value for a transaction"""
0 commit comments