Skip to content

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

Closed
@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

      pFad - Phonifier reborn

      Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

      Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


      Alternative Proxies:

      Alternative Proxy

      pFad Proxy

      pFad v3 Proxy

      pFad v4 Proxy