getIndexFromPosition() should not return index larger than bufferSize #41
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
In my first commit I added a test case that tests the return value of
getIndexFromPosition()
when a position right on the edge is given. Turns out that the function returnstrue
and the returned index is invalid (index is equal to bufferSize). I noticed thatcheckIfPositionWithinMap()
accepts positions that are exactly on the edge of the map but when the index is generated there is no check to validate that the index is still in range.My solution was to modify
checkIfPositionWithinMap()
and not accept positions on the edge of the map. It seems that this change doesn't affect anything else.Another solution (if it is desired to accept edge positions) would be to make sure that the returned index will be in-bounds, in similar fashion as the
limitPositionToRange()
does. In this case, the test that I added in my first commit should pass.Since I am not sure about the desired behavior of
checkIfPositionWithinMap()
regarding edge cases, let me know if something else is indeed affected by this change.