Skip to content

bug: Index will go out of range when RANGE > 2 #288

@HarikrishnanBalagopal

Description

@HarikrishnanBalagopal

Bug

There is a index out of range bug here:

for (let i = 0; i < sortedReleaseDates.length - 1; i++) {
const until = sortedReleaseDates[i + 1].date;
ranges.push([
sortedReleaseDates[i],
{
...sortedReleaseDates[i + RANGE - 1],

The for loop index goes all the way to length - 2 (2nd last element) and we are accessing indices i and i + 1 in the loop.
This only works when RANGE = 2.

When RANGE > 2 we will access indices i and i + RANGE - 1 which will end up outside the range of the array
because we are not changing the for loop end condition.
Example:

RANGE = 3
length = 4
for loop i goes to length - 2 = 4 - 2 = 2
i = 2
i + RANGE - 1 = i + 3 - 1 = i + 2 = 2 + 2 = 4
...sortedReleaseDates[4], // gives a index out of range exception 

Fix

        for (let i = 0; i < sortedReleaseDates.length - RANGE + 1; i++) {

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions