From 7a84fc4742351d7be33b64bd276d03f43e379499 Mon Sep 17 00:00:00 2001 From: Calvin Rose Date: Sat, 16 May 2020 08:28:50 -0500 Subject: [PATCH] Fix infinite loop in some cases. Problem - reusing a tainted variable without reinitializing. --- src/core/specials.c | 1 + test/suite8.janet | 4 ++++ 2 files changed, 5 insertions(+) diff --git a/src/core/specials.c b/src/core/specials.c index 650d43b2..7e9b898b 100644 --- a/src/core/specials.c +++ b/src/core/specials.c @@ -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; diff --git a/test/suite8.janet b/test/suite8.janet index d2556709..8de029d5 100644 --- a/test/suite8.janet +++ b/test/suite8.janet @@ -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)