From e3d7963355786048b5be162c6b217c67d9c73c8f Mon Sep 17 00:00:00 2001 From: Erik Rauer <eriktr22@gmail.com> Date: Thu, 1 Apr 2021 12:04:02 -0500 Subject: [PATCH] Fix `string/set-char` This changes `string/set-char` to throw `:ignore-instruction` when the string is empty. Otherwise the instruction throws a Divide by Zero error. --- src/propeller/push/instructions/string.cljc | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/propeller/push/instructions/string.cljc b/src/propeller/push/instructions/string.cljc index 26398a7..c03ca2e 100755 --- a/src/propeller/push/instructions/string.cljc +++ b/src/propeller/push/instructions/string.cljc @@ -268,10 +268,12 @@ ^{:stacks #{:char :integer :string}} (fn [state] (make-instruction state - #(let [index (mod %2 (count %3)) + #(if (empty? %3) + :ignore-instruction + (let [index (mod %2 (count %3)) beginning (take index %3) end (drop (inc index) %3)] - (apply str (concat beginning (list %1) end))) + (apply str (concat beginning (list %1) end)))) [:char :integer :string] :string)))