Skip to content

Commit

Permalink
Merge pull request #2 from copyleftdev/bias
Browse files Browse the repository at this point in the history
#### Changes:
- **Added overflow check to `parse_hosts_and_biases` function:**
  - Introduced a `total_bias` variable using `u64` to safely sum the biases and avoid overflow.
  - Added a constant `MAX_BIAS` to represent the maximum allowable total bias (`u32::MAX`).
  - Updated logic to check if the total bias exceeds `MAX_BIAS` and return an error if it does.
  - Included a check to ensure bias values are greater than 0, returning an error otherwise.

- **Updated test case `test_bias_overflow_parsing`:**
  - Modified the test case to use bias values that would result in an overflow condition.
  - Verified that `Config::try_parse_from` correctly returns an error when the total bias exceeds the allowable limit.

#### Testing:
- **Tested `parse_hosts_and_biases` function:**
  - Validated correct parsing of valid bias values.
  - Confirmed that invalid bias values (e.g., non-numeric or zero) result in appropriate error messages.
  - Ensured that scenarios where the total bias exceeds `u32::MAX` result in an error.

- **Tested other functions for regressions:**
  - Ran existing unit tests to confirm no unintended side effects or regressions in functionality.

#### Summary:
- This update improves the robustness of the `parse_hosts_and_biases` function by adding defensive programming checks for bias overflow. The changes ensure that users are informed of configuration errors when bias values exceed allowable limits, thereby preventing potential runtime issues.

---

This detailed commit note should help reviewers understand the changes made, the reasons behind them, and the testing conducted to ensure correctness.
  • Loading branch information
copyleftdev committed Jul 10, 2024
2 parents 6d8891c + 6a072c1 commit e6d4c33
Show file tree
Hide file tree
Showing 8 changed files with 641 additions and 189 deletions.
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
/target
.prompt
*.json
*.json
*.py
*.txt
Loading

0 comments on commit e6d4c33

Please sign in to comment.