diff options
author | Malf Furious <m@lfurio.us> | 2018-09-20 00:28:17 -0400 |
---|---|---|
committer | Malf Furious <m@lfurio.us> | 2018-09-20 00:28:17 -0400 |
commit | d16ddc164b82c594680359841eeeaa1e26aceaa1 (patch) | |
tree | 77fc8fda9797c50e42d93703d4abb11e91104a7c /app/class | |
parent | 1daec62c0ab6590d3a30464b2f679baea3ca3936 (diff) | |
download | scrott-d16ddc164b82c594680359841eeeaa1e26aceaa1.tar.gz scrott-d16ddc164b82c594680359841eeeaa1e26aceaa1.zip |
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.
Diffstat (limited to 'app/class')
-rw-r--r-- | app/class/pad.class.php | 3 |
1 files changed, 3 insertions, 0 deletions
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(); } |