From d9c3b83d1ed4e5b04d4ef36e383b206203d5370d Mon Sep 17 00:00:00 2001 From: Giovanni Campagna Date: Tue, 17 Jul 2012 19:27:43 +0200 Subject: [PATCH] Panel: fix finding leftmost and rightmost buttons Previous code would access the array element before checking that the index was within bounds, and therefore cause a TypeError. It wasn't noticed earlier because at least one visible children is in each panel box in all session modes. https://bugzilla.gnome.org/show_bug.cgi?id=619955 --- js/ui/panel.js | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/js/ui/panel.js b/js/ui/panel.js index c969381af..648a67790 100644 --- a/js/ui/panel.js +++ b/js/ui/panel.js @@ -753,10 +753,11 @@ const PanelCorner = new Lang.Class({ return null; // Start at the back and work backward - let index = children.length - 1; - while (!children[index].visible && index >= 0) - index--; - + let index; + for (index = children.length - 1; index >= 0; index--) { + if (children[index].visible) + break; + } if (index < 0) return null; @@ -777,10 +778,11 @@ const PanelCorner = new Lang.Class({ return null; // Start at the front and work forward - let index = 0; - while (!children[index].visible && index < children.length) - index++; - + let index; + for (index = 0; index < children.length; index++) { + if (children[index].visible) + break; + } if (index == children.length) return null;