tari-project / tari

The Tari protocol
https://tari.com
BSD 3-Clause "New" or "Revised" License
350 stars 218 forks source link

chore: use safer slice splitting #6437

Closed AaronFeickert closed 3 months ago

AaronFeickert commented 3 months ago

Description

Ensures that all slice splitting is properly checked to avoid panics.

Motivation and Context

There are a few remaining uses of slice::split_at that are used to split slices. Because this can panic on a bad index, this PR moves each use to slice::split_at_checked, which cannot panic.

How Has This Been Tested?

Existing tests pass.

What process can a PR reviewer use to test or verify this change?

Ensure that each split is still being done at the same index, and that the error handling is done properly.

AaronFeickert commented 3 months ago

Note that this does not include the uses already addressed by #6430.

github-actions[bot] commented 3 months ago

Test Results (CI)

    3 files    116 suites   41m 43s :stopwatch: 1 301 tests 1 300 :white_check_mark: 0 :zzz: 1 :x: 3 785 runs  3 784 :white_check_mark: 0 :zzz: 1 :x:

For more details on these failures, see this check.

Results for commit 3b4dcdd5.

:recycle: This comment has been updated with latest results.

github-actions[bot] commented 3 months ago

Test Results (Integration tests)

 2 files  11 suites   24m 19s :stopwatch: 35 tests 33 :white_check_mark: 0 :zzz: 2 :x: 37 runs  35 :white_check_mark: 0 :zzz: 2 :x:

For more details on these failures, see this check.

Results for commit 3b4dcdd5.

AaronFeickert commented 3 months ago

I also didn't identify any particular problems with the existing implementation. As noted, this was to reduce risk going forward in the event of changes.