forked from ossf/wg-best-practices-os-developers
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
CWE-197 Control rounding when converting to less precise numbers Prior to moving doc as part of ossf#531 Signed-off-by: Helge Wehder <[email protected]>
- Loading branch information
Showing
4 changed files
with
21 additions
and
1 deletion.
There are no files selected for viewing
6 changes: 6 additions & 0 deletions
6
docs/Secure-Coding-Guide-for-Python/CWE-664/CWE-197/01/compliant01.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
# SPDX-FileCopyrightText: OpenSSF project contributors | ||
# SPDX-License-Identifier: MIT | ||
""" Compliant Code Example """ | ||
foo = int(round(0.9)) | ||
type(foo) # class int | ||
print(foo) # 0 |
7 changes: 7 additions & 0 deletions
7
docs/Secure-Coding-Guide-for-Python/CWE-664/CWE-197/01/compliant02.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
# SPDX-FileCopyrightText: OpenSSF project contributors | ||
# SPDX-License-Identifier: MIT | ||
""" Compliant Code Example """ | ||
from decimal import Decimal, ROUND_HALF_UP, ROUND_HALF_DOWN | ||
|
||
print(Decimal("3.5").quantize(Decimal("1"), rounding=ROUND_HALF_UP)) | ||
print(Decimal("3.5").quantize(Decimal("1"), rounding=ROUND_HALF_DOWN)) |
6 changes: 6 additions & 0 deletions
6
docs/Secure-Coding-Guide-for-Python/CWE-664/CWE-197/01/noncompliant01.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
# SPDX-FileCopyrightText: OpenSSF project contributors | ||
# SPDX-License-Identifier: MIT | ||
""" Non-compliant Code Example """ | ||
foo = int(0.9) | ||
type(foo) # class int | ||
print(foo) # |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters