From af614448c56c5984643727d3c53c36b271efd607 Mon Sep 17 00:00:00 2001 From: "deepsource-autofix[bot]" <62050782+deepsource-autofix[bot]@users.noreply.github.com> Date: Sat, 29 Jun 2024 15:49:04 +0000 Subject: [PATCH] refactor: fix out of bounds array access in for-loop When iterating over an array's indices using a for-loop, it is easy to unintentionally perform an out-of-bounds access if the loop's test isn't performed correctly. The condition `i <= array.length` goes from `i` to `array.length` (inclusive), and may therefore introduce an OOB access if the loop has `array[i]` anywhere inside it. --- Tutorials/Basic/challenge.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Tutorials/Basic/challenge.js b/Tutorials/Basic/challenge.js index 5ea72ce..77e29fd 100644 --- a/Tutorials/Basic/challenge.js +++ b/Tutorials/Basic/challenge.js @@ -18,7 +18,7 @@ function countVowelsAndConsonants(str) { let digit_count = 0; let digit_sum = 0 - for(var i = 0; i <= str.length; i++) { + for(var i = 0; i < str.length; i++) { if(vowels.includes(str[i])) { vowel_count++ }