~sircmpwn/rc-devel

This thread contains a patchset. You're looking at the original emails, but you may wish to use the patch review UI. Review patch
1

[PATCH] Fix for loops in interactive mode

Details
Message ID
<20231027041420.31129-1-jturtl@pm.me>
DKIM signature
missing
Download raw message
Patch: +7 -3
Using a for loop in interactive mode will crash because `state.ctx` is empty.
An implied for loop over $*, like `for (arg) echo $arg` would crash as well
because $* is not set in interactive mode.
---
 interp/exec.ha | 10 +++++++---
 1 file changed, 7 insertions(+), 3 deletions(-)

diff --git a/interp/exec.ha b/interp/exec.ha
index fafa10a..5965e5a 100644
--- a/interp/exec.ha
+++ b/interp/exec.ha
@@ -262,8 +262,9 @@ fn exec_for_loop(state: *state, cmd: *ast::for_loop) (int | error) = {
	defer strings::freeall(iter);

	if (len(cmd.values) == 0) {
		const args = get(state, "*") as *variable;
		iter = value_reduce(&args.value);
		const args = get(state, "*");
		if (args != null)
			iter = value_reduce(&(args: *variable).value);
		i = 1z;
	} else {
		let args: []value = [];
@@ -276,7 +277,10 @@ fn exec_for_loop(state: *state, cmd: *ast::for_loop) (int | error) = {
		iter = value_reduce(&(args: value));
	};

	let ctx = pushctx(state, context_type::LOOP, state.ctx[0].args);
	let ctx = if (len(state.ctx) > 0)
		pushctx(state, context_type::LOOP, state.ctx[0].args)
	else
		pushctx(state, context_type::LOOP, []);
	defer popctx(state);

	let st = 0;
--
2.42.0
Details
Message ID
<CWKWGV33U14H.HIXTB6H4B8JR@taiga>
In-Reply-To
<20231027041420.31129-1-jturtl@pm.me> (view parent)
DKIM signature
missing
Download raw message
Thanks!

To git@git.sr.ht:~sircmpwn/rc
   f34f923..35ccdc1  master -> master
Reply to thread Export thread (mbox)