From d16ddc164b82c594680359841eeeaa1e26aceaa1 Mon Sep 17 00:00:00 2001 From: Malf Furious Date: Thu, 20 Sep 2018 00:28:17 -0400 Subject: pad: Fix bug in function getStages() In cases where the pad had no stages beneath it, `new stage($this->stage)` would construct an invalid object. As it turns out, calling ->getArray() on an uninitialized stage object yeilds bad results. Instead of patching the stage::getArray() function, I add a check to harden pad::getStages(). My reasoning for this is as follows: The bug in getArray() manifests from a domain error, ie. it's only because we are calling it on an uninitialized object. The object is already in a bad state prior to caling getArray(). Rather, I opt to patch getStages() so that we never create a bad object in the first place. Now, for no-stage pads, getStages() will return early an empty array. --- app/class/pad.class.php | 3 +++ 1 file changed, 3 insertions(+) (limited to 'app') diff --git a/app/class/pad.class.php b/app/class/pad.class.php index 38812d6..dcf2b32 100644 --- a/app/class/pad.class.php +++ b/app/class/pad.class.php @@ -91,6 +91,9 @@ class pad extends obj */ public function getStages() : array { + if (!isset($this->stage) || $this->stage == "") + return array(); + $stage = new stage($this->stage); return $stage->getArray(); } -- cgit v1.2.3