Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2 from copyleftdev/bias
#### 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