Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix out-of-bounds error on new_replace_table #64

Conversation

andreaskurth
Copy link
Contributor

@andreaskurth andreaskurth commented Aug 2, 2023

The for i in 0..new_replace_table.len() - 1 loop gave me an "index out of bounds: the len is 0 but the index is 0" run-time error. The problem is that the subtraction underflows when the length of the vector is zero, since the LHS is of type usize. (The underflow would lead to an "attempt to subtract with overflow" run-time error with debug builds but not with release builds.)

This commit fixes the problem by ensuring that new_replace_table.len() is at least one before applying the subtraction using .windows(2) to get an iterator over overlapping subslices of length two. (EDIT: A more 'Rusty' solution came to my mind. 🙂 )

The `for i in 0..new_replace_table.len() - 1` loop gave me an "index out
of bounds: the len is 0 but the index is 0" run-time error.  The problem
is that the subtraction underflows when the length of the vector is
zero, since the LHS is of type `usize`.  (The underflow would lead to an
"attempt to subtract with overflow" run-time error with debug builds but
not with release builds.)

This commit fixes the problem by using `.windows(2)` to get an iterator
over overlapping subslices of length two.
@andreaskurth andreaskurth force-pushed the fix-out-of-bounds-error-new_replace_table branch from 991433c to 8158918 Compare August 3, 2023 05:57
Copy link
Member

@micprog micprog left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 👍

@micprog micprog merged commit ff44171 into pulp-platform:master Aug 3, 2023
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants