1
0
mirror of https://github.com/janet-lang/janet synced 2024-06-21 04:39:55 +00:00

Fix infinite loop in some cases.

Problem - reusing a tainted variable without reinitializing.
This commit is contained in:
Calvin Rose 2020-05-16 08:28:50 -05:00
parent 92df01b99d
commit 7a84fc4742
2 changed files with 5 additions and 0 deletions

View File

@ -622,6 +622,7 @@ static JanetSlot janetc_while(JanetFopts opts, int32_t argn, const Janet *argv)
/* Check if closure created in while scope. If so,
* recompile in a function scope. */
if (tempscope.flags & JANET_SCOPE_CLOSURE) {
subopts = janetc_fopts_default(c);
tempscope.flags |= JANET_SCOPE_UNUSED;
janetc_popscope(c);
janet_v__cnt(c->buffer) = labelwt;

View File

@ -281,4 +281,8 @@ neldb\0\0\0\xD8\x05printG\x01\0\xDE\xDE\xDE'\x03\0marshal_tes/\x02
(assert (= nil (peg/match peg2 "1:a2:bb:5:cccccc")) "lenprefix 6")
(assert (= nil (peg/match peg2 "1:a2:bb:7:cccccc")) "lenprefix 7")
# Regression #400
(assert (= nil (while (and false false) (fn []) (error "should not happen"))) "strangeloop 1")
(assert (= nil (while (not= nil nil) (fn []) (error "should not happen"))) "strangeloop 2")
(end-suite)