From 916a3bced3d749ef26203a2240e38d05cb618c1e Mon Sep 17 00:00:00 2001 From: tophf Date: Wed, 30 Aug 2017 20:54:03 +0300 Subject: [PATCH] fixup bf4619fc possible OOB --- edit/edit.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/edit/edit.js b/edit/edit.js index 7e515efa..2e2b25a6 100644 --- a/edit/edit.js +++ b/edit/edit.js @@ -1105,9 +1105,9 @@ function getEditorInSight(nearbyElement) { } function findClosest() { - // side-effect: sets 'cm' of the parent function + const last = editors.length - 1; let a = 0; - let b = editors.length - 1; + let b = last; let c; let cm, distance; while (a < b - 1) { @@ -1117,7 +1117,7 @@ function getEditorInSight(nearbyElement) { break; } const distancePrev = offscreenDistance(c - 1); - const distanceNext = c <= b ? offscreenDistance(c + 1) : 1e20; + const distanceNext = c < last ? offscreenDistance(c + 1) : 1e20; if (distancePrev <= distance && distance <= distanceNext) { b = c; } else {